How to Query Results
Summary
You can query the results of a GET request in our API with specific parameters. Many of those listed below can meet use cases where only specific data is required. For larger data sets, read the Cursor section to learn how to obtain a consistent sort order in the data response.
Parameter | Purpose | Example |
---|---|---|
?where | To pass a string containing a JavaScript expression | /locations?where={"account":"5f327*****f5cd5"\} |
max_results | The limit is 500 results. Only 25 results are returned if this parameter is not set. | ?max_results=500 |
sort | Specify the order in which the query returns the results. Add - for descending e.g. sort=-_created and without for ascending sort=_created | ?sort=-_created |
cursor | View the Cursor section. | ?cursor=new |
$eq | The value of the specified field is equal to a specified value | |
$gte | The value of the specified field is greater than or equal. | "$gte": "YYYY-MM-DDTHH:mm:ss.SSSSSSZ" |
$lte | The value of the specified field is lesser than or equal. | "$lte": "YYYY-MM-DDTHH:mm:ss.SSSSSSZ" |
$size | To match an array to a specified number of elements. | {"$size":5} |
$in | The value of the specified field is equal to any value in the specified array | "$in":[1, 2] |
$ne | Results are returned where the specified value does no exist. | "$ne":"5be9*********46d4" |
$exists | A boolean to filter out results where a value exists or not. | "$exists": true, |
Cursor
When sending a query that returns paged results but no sorting is requested, Deliverect returns the results with a warning:
"`warning": "For more correct paged results, please use sort, cursor or preference"
When paging through results with each page request, our database won't always return the data in the same order.
While you could use ?sort=-_created
to return a consistent order, we recommend that you query using &cursor=new
as this has more reliability.
Here is an example of a Get Locations query:
https://api.deliverect.com/locations?where={"account":"61*********34"}&cursor=new&max_results=500
This provides within the first page of results a "cursor"
ID (view the example below).
All subsequent calls should then pass this ID as &cursor={CURSOR_STRING_FROM_META}
to ensure you are retrieving data from our database using the same cursor point.
},
"_meta": {
"page": 1,
"max_results": 500,
"total": 584,
"cursor": "e8c9b36f***ccfbeff08fe"
}
To page through to the next set of results, subsequent requests would be sent using:
https://api.deliverect.com/locations?where={"account":"61******34"}&cursor=e8c9b36f****eff08fe&max_results=500&page=2
Updated 6 months ago