Filtering and Sorting
Filtering and sorting results can help speed up responses and data collection.
Each section inside the docs that supports filtering will have a list of supported filters defined and you can specify as a query parameter while making the request.
Filters should be provided as a part of the endpoint URL in the following format:
For example, lets say that you want to get all the users that are named
John. It can be done by providing the
searchfilter while making the request:
There are two different types of filters, the
Exact filters will only return those records where a specific attribute is exactly the same as the provided filter value.
For example, if an endpoint supports an exact filter for filtering out the records by status and if you provide
?filter[status]=1query parameter, only records that have the
statusattribute set to
1will be returned.
The partial filters are usually used for text based fields an it will return all the records that have the provided filter vaule anywhere within the attribute value.
For example, if there is a filter
namedefined for the specific resource and you provide the
?filter[name]=onefilter within the URL, the API will return all the customers from the db that contain the word
oneanywhere within their
nameattribute and not only those who has the name exactly set as
All sortable resources will provide the list of sortable fields that can be used for sorting the data that is being returned from the API.
To sort a resource by the specific field, just append the
?sort=FIELDquery parameter while you make the request to the API endpoint and it will sort the items in
ascendingorder. To sort the items in
descendingorder, prefix the field with
For example, if you want to sort the users in
ascendingorder by the
created_attimestamp, you should make a request to the following endpoint:
If you want to sort them by the
descendingorder, the enpoint should be updated to look like the following: