> For the complete documentation index, see [llms.txt](https://docs.commercelayer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.commercelayer.io/metrics/getting-started/use-cases/orders-by-day.md).

# Orders by day

How to use the Metrics API to get the total number of orders of your organization, grouped by day

### The problem

You want to get the total number of orders over a selected date and time range, grouped by day.

### The solution

#### Query

You need to perform a [date breakdown query](/metrics/getting-started/queries/date-breakdown.md) setting the required query keys as follows and adding the optional ones based on your needs:

| Key            | Value                |
| -------------- | -------------------- |
| **`by`**       | `order.current_date` |
| **`field`**    | `order.id`           |
| **`operator`** | `value_count`        |
| **`interval`** | `day`                |

{% hint style="info" %}
Change the `interval` key if you want to group the results differently (e.g. by `year` or `hour` — default is `month`).
{% endhint %}

#### Filter

Make sure to set the desired date and time range using the `date_from` and `date_to` keys in the [filter](/metrics/getting-started/filters.md).&#x20;

In this example, since the `date_field` isn't specified, the default value `current_date` will be used. Being the same date time field used in the `by` key of the query, you'll get in the response all the orders that actually changed their status each day within the selected date and time range ([read more](/metrics/getting-started/filters.md#combining-date-filters-and-date-breakdown-queries) about this).

### [Try it on Postman](https://www.postman.com/commercelayer/workspace/commerce-layer-public-workspace/documentation/19711194-37a2d863-72f6-4b8f-8146-2f61d405fd3c?entity=request-19711194-582c1d0b-78ff-4d1a-be8e-abeaefdb608b) :rocket:

### Example

{% tabs %}
{% tab title="Request" %}
The following request uses the Metrics API to get the total number of orders, grouped by day:

<pre class="language-shell"><code class="lang-shell">curl -g -X POST \
  'https://{{your_domain}}.commercelayer.io/metrics/orders/date_breakdown' \
  -H 'Accept: application/vnd.api.v1+json' \
  -H 'Content-Type: application/vnd.api+json' \
  -H 'Authorization: Bearer {{your_access_token}}' \
  -d '{
    "date_breakdown": {
<strong>      "by": "order.current_date",
</strong><strong>      "field": "order.id",
</strong><strong>      "operator": "value_count",
</strong><strong>      "interval": "day"
</strong>    },
    "filter": {
      "order": {
        "date_from": "2021-01-01T00:00:00Z",
        "date_to": "2021-12-31T23:59:00Z"
      }
    }
  }'
</code></pre>

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the aggregated values in the `data` object and extra information in the `meta` object:

```json
{
  "data": [
    {
      "date": "2021-01-01T00:00:00.000Z",
      "value": 1196
    },
    {
      "date": "2021-01-02T00:00:00.000Z",
      "value": 1371
    },
    {
      "date": "2021-01-03T00:00:00.000Z",
      "value": 1574
    },
    {
      "date": "2021-01-04T00:00:00.000Z",
      "value": 1735
    },
    { ... },
    {
      "date": "2021-12-30T00:00:00.000Z",
      "value": 2344
    },
    {
      "date": "2021-12-31T00:00:00.000Z",
      "value": 1905
    }
  ],
  "meta": {
    "type": "date_breakdown",
    "trace_id": "fe571ea2-8a4f-4a5e-bd26-ac54651bb2e4",
    "mode": "test",
    "organization_id": "xYZkjABcde",
    "market_ids": [ "yzXKjYzaCx", "..." ]
  }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.commercelayer.io/metrics/getting-started/use-cases/orders-by-day.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
