# Export

To export carts as CSV send a `POST` request to the `/carts/export` endpoint specifying in the payload the [query keys](#query-keys) and [filter](https://docs.commercelayer.io/metrics-api-reference/resources/carts/filters) 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](https://app.gitbook.com/s/ASSiAvbL4nFnkl8plQy2/getting-started/queries/export).
{% 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>order.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>["order.id", "order.placed_at", "order.total_amount_with_taxes"]</code>.</td></tr></tbody></table>

### `sort_by` values

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

* `order.created_at`
* `order.current_date`
* `order.updated_at`

### `field` values

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

* `billing_address.business`
* `billing_address.city`
* `billing_address.country_code`
* `billing_address.geocoded`
* `billing_address.localized`
* `billing_address.state_code`
* `billing_address.zip_code`
* `customer.email`
* `customer.group_name`
* `customer.id`
* `customer.reference`
* `customer.reference_origin`
* `market.id`
* `market.name`
* `market.number`
* `order.adjustment_amount`
* `order.adjustment_tax_amount`
* `order.adjustment_taxable_amount`
* `order.affiliate_code`
* `order.aggregated_details`
* `order.country_code`
* `order.coupon`
* `order.coupon_code`
* `order.created_at`
* `order.currency_code`
* `order.current_date`
* `order.customer_type`
* `order.discount_amount`
* `order.discounted`
* `order.duty_amount`
* `order.freight_taxable`
* `order.fulfillment_status`
* `order.gift_card`
* `order.gift_card_amount`
* `order.gift_card_code`
* `order.guest`
* `order.id`
* `order.language_code`
* `order.line_item_options_count`
* `order.link_id`
* `order.mode`
* `order.number`
* `order.options`
* `order.payment_method_amount`
* `order.payment_method_tax_amount`
* `order.payment_method_taxable_amount`
* `order.payment_status`
* `order.reference`
* `order.reference_origin`
* `order.shipments_count`
* `order.shipping_amount`
* `order.shipping_taxable_amount`
* `order.skus_count`
* `order.status`
* `order.store_id`
* `order.subtotal_amount`
* `order.subtotal_tax_amount`
* `order.subtotal_taxable_amount`
* `order.tax_included`
* `order.total_amount`
* `order.total_amount_with_taxes`
* `order.total_tax_amount`
* `order.total_taxable_amount`
* `order.updated_at`
* `order.user_id`
* `organization.id`
* `organization.name`
* `organization.slug`
* `payment_method.id`
* `payment_method.moto`
* `payment_method.name`
* `payment_method.source_type`
* `shipping_address.business`
* `shipping_address.city`
* `shipping_address.country_code`
* `shipping_address.geocoded`
* `shipping_address.localized`
* `shipping_address.state_code`
* `shipping_address.zip_code`
* `tags.id`
* `tags.name`

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