Search
How to perform a search query and how it works
Searches are a type of query a bit different from the other ones (breakdowns, date breakdowns, and stats). 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 response the list of the requested fields
(sorted, filtered, and paginated) of the actual records that match the query.
Request
To perform a search query send a POST
request to the /{{resource_name}}/search
endpoint specifying the query keys and filter parameters:
Query keys
Key | Type | Required | Description | Values |
---|---|---|---|---|
| Integer | The maximum number of records shown in the response. | Default is | |
| String | The way you want the results of the query to be sorted. | One of | |
| String | The date field you want the results of the query sorted by. | ||
| Array | The list of fields you want to be returned for each record in the response. | The available values for this key depend on the resource you're searching (see orders, returns, or carts for the related lists). Cannot be empty. Use | |
| String | The cursor pointing to a specific page in the paginated search results. | Every time you perform a search query you get the cursor to the next page in the |
Requesting all the field's attributes
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 example).
Response
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:
Pagination
Unlike the other types of queries (breakdowns, date breakdowns, and stats) 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
:
Field | Type | Description |
---|---|---|
| Integer | The total number of records that match the query. |
| String | The cursor pointing to the next page ( |
The value of the cursor
can be added to the request payload to get that specific page's records in the response (see example).
Examples
The following examples will be focused on the query part of the request. So no specific filter or meta options will be defined (i.e. all the results will be filtered by the default filter and the response won't include the request payload). See the use cases section for more complex combinations of queries and filters.
Requesting specific fields
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:
Requesting all the attributes for some fields
The following request performs a search query to get all the available fields for the last two orders placed and the associated customers:
Requesting a specific page from the paginated results
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:
Last updated