Export
How to perform an export query and how it works
Exports are a special kind of search query where the result data are converted into a tabular format (CSV). When performing an export query on the Metrics API endpoint, you get in the response a CSV file (text/csv) returned inline, containing the requested fields (sorted and filtered) of the actual records that match the query.
The maximum size allowed for the results of an export query is 100K records. Export queries matching a higher number of records will return a 422 UNPROCESSABLE ENTITY error.
Request
To perform an export query, send a POST request to the /{{resource_name}}/export endpoint specifying the query keys and filter parameters:
{
"search": {
"sort": "...",
"sort_by": "...",
"fields": [ ... ]
},
"filter": { ... }
}Query keys
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 exported for each record.
The available values for this key depend on the resource you're searching (see orders, returns, or carts for the related lists). If empty, default fields will be exported.
Allowed and default fields
Unlike in the search query:
Only the root resource (i.e. order or return) and single-level references are allowed (e.g. no line items or return line items).
No meta information is returned.
No pagination is available for the results (all the records will be exported up to the maximum limit allowed).
Response
The response of an export query is a plain CSV file (text/csv) returned inline and containing a maximum of 100K records, sorted by the date field specified in the sort_by key. For each record, all the fields requested in the fields array (if specified) are exported.
In case of multiple tags for the same resource, tags.name and tags.id will generate space-separated values within the related table column (see example).
Examples
The following examples will focus on the query part of the request. No specific filter will be defined (i.e. all the results will be filtered by the default filter). See the use cases section for more complex combinations of queries and filters.
Default export
The following request performs an export query with an empty body to export as CSV the default fields of the matching orders, sorted by the default date field (i.e. the order's latest status change):
On success, the API responds with a 200 OK status code, returning inline the default data in a plain CSV (text/csv) format:
Exporting specific fields
The following request performs an export query to get information about the orders ID, last time of update, the associated customer ID and email, and the orders tags name (if any), sorted in ascending order by the time when they were updated:
On success, the API responds with a 200 OK status code, returning inline the requested data in a plain CSV (text/csv) format:
Last updated