1. Help Center
  2. API
  3. Mohawk API (deprecated)

Advanced API Queries

The advanced applications of Mohawk Automation (API) and complex queries and how to execute them.

The Legentic Mohawk Automation (API) is our direct connection to our data. This documentation is ideation, it gives the customer a set of possible applications and inspiration. Not all might be applicable, but we’ve tried to label the examples to quickly find inspiration relevant to you.

This document contains a quick overview of the /query path.

Query search

Situation: integrating with the fraud or claims system might require more complicated and combined queries. You might want to check that, for example, both a phone number and license plate that are associated with a customer are both available. 

Solution: We have exposed a \query endpoint. This allows customers to create combined queries and pass them as a JSON file to our endpoint. That JSON will be parsed and used to limit or expand on the search.

A potential user might want to check that either information about the car, with example license_plate = DN94214, and the owner’s phone number, with example phone_number = 46856189 are in our datasets.

We first need to construct a JSON with the general format, or payload structure:

query = '{
"any": {
"key": ["value"]
},
"all": {
"key": ["value"]
},
"none": {
"key": ["value"]
}
}'

any, all, and none stands for operators OR, AND and NOT. Keys are email, ⁣text, author, phone, vin, license_plate / registry_plate, site, price and published. Values are in the JSON array literals, except price and published. Multiple values can be kept in JSON array literals as “text" : ["Volvo", "Audi"].

Where we can populate any of the fields with information we want to expand or limit on. Let’s see how that works for our example:

query = '{
"all": {
"license_plate": ["DN94214"],
"phone": ["46856189"]
},
}'

Which translates to: license_plate = "DN94214" AND phone_number = "46856189"

Additionally, you can constrain the price and published as follows:

query = '{"any":
{ "text":["audi","bmw"]},
"none":
{ "text":["part"],
"price":{"lowerValue":100,"upperValue":1000}}}'

Which translates to: (text = "audi" OR text = "bmw") AND NOT text = "part" AND NOT price in [100, 1000].

Note: that the query needs to be encapsulated by single quotation marks: '<json query>' and should not have any tabs, enters (only for readability in the examples) or special characters (tabs above are only for read-ability).

Also, note that if there are no price or date ranges are given, a default value is inserted.

Python:

import json
import requests


url = 'https://api.mohawkanalytics.com/classifiedads/gb/v1/query'

query_dict = {
'any': {
'text': ['audi', 'bmw']
},
'none': {
'text': ['part'],
'price': {
'lowerValue': 100,
'upperValue': 1000
}
}
}

query = json.dumps(query_dict)

headers = {'API-Key':'<YOUR_API_KEY>'}
data = {'query': query, 'limit': 20, 'offset': 0, 'select': None}

resp = requests.post(url, json=data, headers=headers)

print(resp.json())

 Curl:

curl -X 'POST' \
'https://api.mohawkanalytics.com/classifiedads/gb/v1/query' \
-H 'accept: application/json' \
-H 'API-Key: <YOUR_API_KEY>' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'query=%7B%22any%22%3A%7B%22text%22%3A%5B%22audi%22%2C%22bmw%22%5D%7D%2C%22none%22%3A%7B%22text%22%3A%5B%22part%22%5D%2C%22price%22%3A%7B%22lowerValue%22%3A100%2C%22upperValue%22%3A1000%7D%7D%7D%0A&limit=20&offset=0&select=&date_start=&date_end='

Which gives the user response of:

...
'count': 24171954,
'documents': [{'fields': {'author': 'Loughton Motor Co',
'image_url': ['https://i.ebayimg.com/00/s/NzY4WDEwMjQ=/z/LPAAAOSwrXhiw-7-/$_86.JPG',
'https://i.ebayimg.com/00/s/NzY4WDEwMjQ=/z/BXoAAOSwdnNiw-7~/$_86.JPG',
'https://i.ebayimg.com/00/s/NzY4WDEwMjQ=/z/NSMAAOSwFFRiw-7-/$_86.JPG',
'https://i.ebayimg.com/00/s/NzY4WDEwMjQ=/z/1oIAAOSwqMhiw-79/$_86.JPG',
'https://i.ebayimg.com/00/s/NzY4WDEwMjQ=/z/UgkAAOSwIydiw-79/$_86.JPG',
'https://i.ebayimg.com/00/s/NzY4WDEwMjQ=/z/pikAAOSwBCFiw-79/$_86.JPG',
'https://i.ebayimg.com/00/s/NzY4WDEwMjQ=/z/CtEAAOSwa2Viw-79/$_86.JPG'],
'page-title': '1987 BMW 6 Series 635 CSiA 2dr Coupe Petrol Manual | in Loughton, Essex | Gumtree',
'classifiedads_id': 'www.gumtree.com-1436630087',
'url': 'https://www.gumtree.com/p/bmw/1987-bmw-6-series-635-csia-2dr-coupe-petrol-manual/1436630087',
'published_estimated': '2022-07-11 08:32:12 +0000',
'price': '28000.0',
'name': '1987 BMW 6 Series 635 CSiA 2dr Coupe Petrol Manual',
'location': 'Loughton, Essex',
'author-uri': 'https://www.gumtree.com/sellerads/1436630087?page=1',
'text': 'Overview Performance Year 1987 Mileage 110,000 miles Body Type Coupe Transmission Manual Colour Red . Description: Description 1987, BMW, 6 SERIES, 635 CSiA 2dr, 2 Doors, Coupe, Red, 28000GBP, Petrol, 3430, 110000 Safety Belt Pretensioners Ad ID: 1436630087VAT number: 206915905 Exact specification may vary from the details on this page. Please contact the seller to reconfirm any details before purchasing. See Terms &amp; Conditions for further information.',
'category': 'Cars > BMW > BMW 6 SERIES'}},
...

 

There you have it, this is how to get started with the query path. You can make the queries as complicated as wanted or necessary. Good luck! 

 

One final note regarding the any operator. The Any operator is supposed to work as an OR if your query provides multiple values for a certain key. So:

returns all results that have text = Volvo OR text = Audi.
In case you provide multiple key-value pairs in the any operator, then it is expected that the keys work as an AND search. It means that:
 
 

will return all results that have text = Volvo OR text = Audi AND phone = +4712345678 OR phone = +4787654321.