Skip to main content

Filtering and Sorting Results

The Fleetio API supports query parameters for both filtering and sorting results from index endpoints. We have started a transition away from the use of q[] style filtering and sorting towards simpler filter and sort url parameter filtering and sorting. Newer endpoints that accept the filter and sort query parameters will not accept the q[] style filtering parameter.

info

The new filtering and sorting methods only exist in API versions starting with 2024-01-01. They can be identified by the response, which returns an object with pagination data, applied filters and sorts, and the array of records in the records attribute.

New filtering and sorting method (for endpoints which accept filter and sort query params)

Filtering

We use the filter parameter to indicate the filters to be applied, and return the filtered_by response attribute to confirm the filters applied to a response.

For example, to only return Vehicles with name including "Tundra":

https://secure.fleetio.com/api/v1/vehicles?filter[name][like]=Tundra

Sorting

We use the sort parameter to indicate the sorts to be applied, and return the sorted_by response attribute to confirm the sorts applied to a response.

For example, to sort Vehicles by "created_at" from oldest to newest:

https://secure.fleetio.com/api/v1/vehicles?sort[created_at]=asc

Original filtering and sorting method, (for endpoints which do not accept filter and sort query params)

Filtering

We use the q[] parameter to differentiate filters from regular parameters.

For example, to only return Vehicles with model year 2018 or later:

https://secure.fleetio.com/api/v1/vehicles?q[year_gteq]=2018

You can provide more than one filter to a request. The server will combine the filters using a logical AND operator. It does not support the OR operation. The best solution for this is to send several requests.

Sorting

We treat sorting as just another q[] wrapped predicate, q[s].

For example, to sort Vehicles by year in descending order:

https://secure.fleetio.com/api/v1/vehicles?q[s]=year+desc

Predicate Reference

PredicateDescriptionExample
eqEquals. Case sensitive.q[id_eq]=321
matchesField should match the given value. Similar to SQL's LIKE operator. Case insensitive.q[license_plate_matches]=wx123yz
ltLess than.q[started_at_lt]=2023-01-01
lteqLess than or equal to.q[completed_at_lteq]=2023-01-31
gtGreater than.q[discount_percentage_gt]=10
gteqGreater than or equal to.q[total_amount_gteq]=500
contContains. Used for matching partial strings.q[license_plate_cont]=23y
in_sEqual to an item in a list. Similar to SQL's IN operator. Accepts a string of comma separated values. Case sensitive.q[color_in_s]=Yellow,Green
trueBoolean operator for true. Accepts 1 as a value.q[secondary_meter_true]=1
falseBoolean operator for false. Accepts 1 as a value.q[secondary_meter_false]=1
presentNot null and not a blank string. Accepts 1 as a value.q[vin_present]=1
nullIs null. Accepts 1 as a value.q[vin_null]=1
sUsed for sorting.
Accepts attribute, attribute+asc, or attribute+desc as a value.
Defaults to asc if only attribute is passed.
q[s]=created_at+desc

Please see our Filtering and Sorting guides to learn more.