# Stats

To perform a stats query on the return resource send a `POST` request to the `/returns/stats` endpoint specifying in the payload the [query keys](#query-keys) and [filter](https://docs.commercelayer.io/metrics-api-reference/resources/returns/filters) parameters like in the generic example below:

```json
{
  "stats": {
    "field": "...",
    "operator": "..."
  },
  "filter": { ... }
}
```

{% hint style="info" %}
Please find more information on how stats queries work [here](https://app.gitbook.com/s/ASSiAvbL4nFnkl8plQy2/getting-started/queries/stats).
{% endhint %}

### Query keys

These are the keys you need to set when performing a stats 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>field</code></strong></td><td>String</td><td>true</td><td>The field you want the metrics or statistics computed on.</td><td>See the <a href="#operators-and-field-values">table below</a> to check the full list of valid values for this key.</td></tr><tr><td><strong><code>operator</code></strong></td><td>String</td><td>false</td><td>The computing operator.</td><td>See the <a href="../breakdown#operators-and-field-values">table below</a> to check the full list of valid operators based on the value you assigned to the <code>field</code> key. Default is <code>sum</code>.</td></tr></tbody></table>

### Operators and `field` values

These are the valid values you can specify for the `field` key of the stats query and the related valid operators, based on that key:

| Value                                          | Operators                                                                                                             |
| ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
| **`customer.id`**                              | `value_count`                                                                                                         |
| **`customer.email`**                           | `value_count`                                                                                                         |
| **`customer.group_name`**                      | `value_count`                                                                                                         |
| **`destination_address.business`**             | `value_count`                                                                                                         |
| **`destination_address.city`**                 | `value_count`                                                                                                         |
| **`destination_address.country_code`**         | `value_count`                                                                                                         |
| **`destination_address.geocoded`**             | `value_count`                                                                                                         |
| **`destination_address.localized`**            | `value_count`                                                                                                         |
| **`destination_address.state_code`**           | `value_count`                                                                                                         |
| **`destination_address.zip_code`**             | `value_count`                                                                                                         |
| **`origin_address.business`**                  | `value_count`                                                                                                         |
| **`origin_address.city`**                      | `value_count`                                                                                                         |
| **`origin_address.country_code`**              | `value_count`                                                                                                         |
| **`origin_address.geocoded`**                  | `value_count`                                                                                                         |
| **`origin_address.localized`**                 | `value_count`                                                                                                         |
| **`origin_address.state_code`**                | `value_count`                                                                                                         |
| **`origin_address.zip_code`**                  | `value_count`                                                                                                         |
| **`market.id`**                                | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`market.number`**                            | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`return.number`**                            | `value_count`                                                                                                         |
| **`return.reference`**                         | `value_count`                                                                                                         |
| **`return.reference_origin`**                  | `value_count`                                                                                                         |
| **`return.status`**                            | `value_count`                                                                                                         |
| **`return.id`**                                | <p><code>cardinality</code></p><p><code>value\_count</code></p>                                                       |
| **`return.order_id`**                          | `value_count`                                                                                                         |
| **`return.skus_count`**                        | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`return_line_items.quantity`**               | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`return_line_items.line_item_id`**           | `value_count`                                                                                                         |
| **`return_line_items.line_item_name`**         | `value_count`                                                                                                         |
| **`return_line_items.line_item_code`**         | `value_count`                                                                                                         |
| **`return_line_items.line_item_item_type`**    | `value_count`                                                                                                         |
| **`return_line_items.line_item_total_amount`** | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`return_line_items.line_item_tax_amount`**   | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`return_line_items.line_item_tax_rate`**     | <p><code>avg</code></p><p><code>max</code></p><p><code>min</code></p><p><code>sum</code></p><p><code>stats</code></p> |
| **`stock_location.id`**                        | `value_count`                                                                                                         |
| **`stock_location.name`**                      | `value_count`                                                                                                         |
| **`stock_location.reference`**                 | `value_count`                                                                                                         |
| **`stock_location.reference_origin`**          | `value_count`                                                                                                         |
