Skip to content

REST API

Filtering, searching and sorting

Listings in the REST API can be narrowed with filters and put in a different order. This article explains the q parameter, its predicates, several values, search and sorting.

Each condition is one entry in q, named q[<field>_<predicate>]. Several conditions combine with AND:

GET /api/rest/v1/units?q[name_cont]=A1&q[state_eq]=available

Each listing declares in the REST API reference which fields it filters on and, for fields with fixed values, which values exist. A field the listing does not offer is refused with 400.

Predicate Meaning
_eq, _not_eq equals, does not equal
_in, _not_in is one of, is none of
_cont, _not_cont contains, does not contain
_i_cont, _not_i_cont contains, does not contain, ignoring case
_start, _not_start begins with, does not begin with
_end, _not_end ends with, does not end with
_matches, _does_not_match matches a SQL LIKE pattern, where % stands for any run of characters
_lt, _lteq, _gt, _gteq less than, less than or equal, greater than, greater than or equal
_dategteq, _datelteq on or after, on or before that date, ignoring the time of day
_null, _not_null is null (true) or not (false), and the reverse
_present, _blank neither null nor empty, null or empty
_true, _not_true, _false, _not_false boolean tests

Which predicates a field accepts depends on its kind. Text pattern predicates such as _cont work only on text; ordering predicates are not offered for IDs and fixed-value fields. The OpenAPI document publishes these rules in machine-readable form, as x-filter-classes at the top and x-filter on each listing.

Predicates that take a value also accept an _any or _all suffix to match against several values, for example q[name_cont_any][].

_in, _not_in and every _any or _all compound take one parameter per value:

GET /api/rest/v1/units?q[state_in][]=available&q[state_in][]=booked

A comma is not a separator, because names can contain commas. On a free text field the mistake is not caught: q[name_in]=Meier,Schmidt searches for the literal name Meier,Schmidt and returns an empty list. Make sure your client library does not split values on commas.

Fields with fixed values, such as states, types and roles, accept only members of their set. Any other value is refused with 400, and the message names the parameter and the value. The reference lists the valid values.

Some personal data is stored encrypted. An account’s name cannot be compared at all; email and invitation_email accept _eq for an exact address and nothing else. To find people by name or part of an address, use _search, which queries a search index:

GET /api/rest/v1/accounts?q[name_or_email_search]=alex

A search tolerates typos and matches words and prefixes. _or_ joins searchable fields, and the matches are combined. Today only accounts are searchable. If the search index is unavailable, the listing answers 503 rather than a wrong result.

Every search response carries X-Search-Truncated. true means a very broad term hit the candidate limit and the listing is incomplete however far you page. Narrow the term instead.

q[s] takes a field and asc or desc, and replaces the listing’s default order:

GET /api/rest/v1/interaction_requests?q[s]=requested_at%20desc

Each listing declares the fields it sorts on. Any other field, and any encrypted field, is refused with 400.

How refusals look is described in Errors.