Filtering

Filtering

There are different things you can apply to data before being returned.

fields

type: string[]

It specifies which fields should be picked from the car object.

e.g., pick url and vin car fields:

curl 'https://api.teslahunt.io/cars' \
  --get \
  --data-urlencode 'fields.0=url' \
  --data-urlencode 'fields.1=vin' \
  --header 'x-api-key: YOUR_TOKEN'

If you don't need every field, you can use this parameter to reduce the amount of data transferred.

filterByFormula

type: string

A formula represents a set of conditions to be satisfied by the data returned.

You can apply conditions for any of the car object fields.

e.g, filter results by country:

curl 'https://api.teslahunt.io/cars' \
  --get \
  --data-urlencode 'filterByFormula=AND({country} = "Italy")' \
  --header 'x-api-key: YOUR_TOKEN'

e.g, filter results by model:

curl 'https://api.teslahunt.io/cars' \
  --get \
  --data-urlencode 'filterByFormula=AND({modelLetter} = "3")' \
  --header 'x-api-key: YOUR_TOKEN'

e.g, filter results by country AND model:

curl 'https://api.teslahunt.io/cars' \
  --get \
  --data-urlencode 'filterByFormula=AND({country} = "Italy", {modelLetter} = "3")' \
  --header 'x-api-key: YOUR_TOKEN'

sort

type: string[]

A list of sort objects that specifies how the records will be ordered.

e.g, sort results by ascending price:

curl 'https://api.teslahunt.io/cars' \
  --get \
  --data-urlencode 'sort.0.field=price' \
  --data-urlencode 'sort.0.direction=asc' \
  --header 'x-api-key: YOUR_TOKEN'

Each sort object must have a field key specifying the name of the field to sort on, and an optional direction key that is either "asc" or "desc".

maxRecords

type: number

The maximum total number of records that will be returned in your requests.

e.g, get just the first result:

curl 'https://api.teslahunt.io/cars' \
  --get \
  --data-urlencode 'maxRecords=1' \
  --header 'x-api-key: YOUR_TOKEN'