Search
How to perform a search query and how it works
Last updated
How to perform a search query and how it works
Last updated
Searches are a type of query a bit different from the other ones (, , and ). A search is not an aggregation and doesn't involve any computation based on operators, but an actual search. When performing a search query on the Metrics API endpoint you get in the the list of the requested fields
(sorted, filtered, and ) of the actual records that match the query.
To perform a search query send a POST
request to the /{{resource_name}}/search
endpoint specifying the and parameters:
limit
Integer
The maximum number of records shown in the response.
Default is 50
, max is 100
.
sort
String
The way you want the results of the query to be sorted.
One of asc
or desc
(default is desc
).
sort_by
String
The date field you want the results of the query sorted by.
fields
Array
The list of fields you want to be returned for each record in the response.
cursor
String
Every time you perform a search query you get the cursor to the next page in the pagination
object.
The response of a search query returns an array of objects containing a number of records equal to (or less than) the one specified in the limit
key, sorted by the date field specified in the sort_by
key. For each record all the fields requested in the fields
array are returned:
record_count
Integer
The total number of records that match the query.
cursor
String
The cursor pointing to the next page (null
if record_count < limit
).
The following request performs a search query to get information about the orders total amount, currency, alongside the associated customer email and shipping address information, sorted by the time when they were placed:
The following request performs a search query to get all the available fields for the last two orders placed and the associated customers:
The following request performs a search query to get information about the number of shipments associated with the orders and their fulfillment status, sorted by the time of the last fulfillment status update. A specific page in the paginated results is requested:
The available values for this key depend on the resource you're searching (see , , or for the related lists). Default is {{resource_name}}.current_date
(i.e. the datetime of the resource's latest status change).
The available values for this key depend on the resource you're searching (see , , or for the related lists). Cannot be empty. Use {{field_name}}.*
to .
The cursor pointing to a specific page in the search results.
In some cases, you may need to get in the search results all the attributes of some fields for each record. If so, you can use the .*
syntax in the request. Just add {{field_name}}.*
to the field
array for each field you want to fully detail (see ).
Unlike the other types of queries (, , and ) when performing a search query on the Metrics API endpoint you get paginated results. You can find the info you need to navigate through the pages in the pagination
object of the response's meta
:
The value of the cursor
can be added to the request payload to get that specific page's records in the response (see ).
The following examples will be focused on the part of the request. So no specific or options will be defined (i.e. all the results will be filtered by the and the response won't include the request payload). See the section for more complex combinations of queries and filters.