# Export

To export returns as CSV send a `POST` request to the `/returns/export` endpoint specifying in the payload the [query keys](#query-keys) and [filter](/metrics-api-reference/resources/returns/filters.md) parameters like in the generic example below:

```json
{
  "search": {
    "sort": "...",
    "sort_by": "...",
    "fields": [ "...", "...", ... ]
  },
  "filter": { ... }
}
```

{% hint style="info" %}
The response is a CSV file (text/csv) returned inline (maximum size allowed is **100K** records). Please find more information on how export queries work [here](/metrics/getting-started/queries/export.md).
{% endhint %}

### Query keys

These are the keys you need to set when performing an export query:

<table><thead><tr><th>Key</th><th>Type</th><th data-type="checkbox">Required</th><th>Description</th><th>Values</th></tr></thead><tbody><tr><td><strong><code>sort</code></strong></td><td>String</td><td>false</td><td>The way you want the results of the query to be sorted.</td><td>One of <code>asc</code> or <code>desc</code> (default is <code>desc</code>).</td></tr><tr><td><strong><code>sort_by</code></strong></td><td>String</td><td>false</td><td>The date field you want the results of the query sorted by.</td><td><a href="#sort_by-values">Here</a> the full list of valid values for this key. Default is <code>return.current_date</code>.</td></tr><tr><td><strong><code>fields</code></strong></td><td>Array</td><td>false</td><td>The list of fields you want to be exported for each record.</td><td><a href="#field-values">Here</a> the full list of valid values for this key. Default is <code>["return.id", "return.created_at", "return.status"]</code>.</td></tr></tbody></table>

### `sort_by` values

These are the valid values you can specify for the `sort_by` key of the export query:

* `return.approved_at`
* `return.archived_at`
* `return.cancelled_at`
* `return.created_at`
* `return.current_date`
* `return.received_at`
* `return.rejected_at`
* `return.shipped_at`
* `return.updated_at`

### `field` values

These are the valid values you can specify for the `fields` key of the export query:

* `customer.email`
* `customer.group_name`
* `customer.id`
* `destination_address.business`
* `destination_address.city`
* `destination_address.country_code`
* `destination_address.geocoded`
* `destination_address.localized`
* `destination_address.state_code`
* `destination_address.zip_code`
* `market.id`
* `market.name`
* `market.number`
* `organization.id`
* `organization.name`
* `organization.slug`
* `origin_address.business`
* `origin_address.city`
* `origin_address.country_code`
* `origin_address.geocoded`
* `origin_address.localized`
* `origin_address.state_code`
* `origin_address.zip_code`
* `return.aggregated_details`
* `return.approved_at`
* `return.archived`
* `return.archived_at`
* `return.cancelled_at`
* `return.created_at`
* `return.currency_code`
* `return.current_date`
* `return.id`
* `return.mode`
* `return.number`
* `return.order_id`
* `return.received_at`
* `return.reference`
* `return.reference_origin`
* `return.rejected_at`
* `return.shipped_at`
* `return.skus_count`
* `return.status`
* `return.updated_at`
* `stock_location.id`
* `stock_location.name`
* `stock_location.reference`
* `stock_location.reference_origin`
* `tags.id`
* `tags.name`

{% hint style="warning" %}
Only return and single-level references are allowed (no return line items). `tags.name` and `tags.id` generate space-separated values.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.commercelayer.io/metrics-api-reference/resources/returns/export.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
