Enabled resource errors field for orders and carts —
Check the use case
LogoLogo
Metrics APIOther APIsChangelog
Getting started
Getting started
  • Welcome to Metrics API
  • Getting started
    • API specification
    • Queries
      • Breakdown
      • Date breakdown
      • Stats
      • Search
    • Filters
    • Analysis
      • FBT
    • Errors
    • Use cases
      • Orders by currency
      • Orders by status and payment status
      • Orders by repeat customer
      • Orders by bundle
      • Orders by shipment status and shipping method name
      • Orders paid with gift cards
      • Orders associated with a specific promotion
      • Number of products per order by country
      • Best-selling products by market
      • Customers that bought a specific product
      • Shipments average time in picking
      • Top 10 spenders by currency
      • Orders by day
      • Returns per year by destination city
      • Refunds by country and currency
      • Latest carts with a specific product from a specific market
      • Orders by resource error code and message
      • Latest archived orders
      • Latest placed orders from customers with specific email domains
      • Frequently bought together products
  • API reference
    • Orders
    • Returns
    • Carts
On this page
  • The problem
  • The solution
  • Try it on Postman
  • Example
  1. Getting started
  2. Use cases

Orders by day

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

PreviousTop 10 spenders by currencyNextReturns per year by destination city

Last updated 1 year ago

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 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

Change the interval key if you want to group the results differently (e.g. by year or hour — default is month).

Filter

Make sure to set the desired date and time range using the date_from and date_to keys in the .

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 ( about this).

Example

The following request uses the Metrics API to get the total number of orders, grouped by day:

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": {
      "by": "order.current_date",
      "field": "order.id",
      "operator": "value_count",
      "interval": "day"
    },
    "filter": {
      "order": {
        "date_from": "2021-01-01T00:00:00Z",
        "date_to": "2021-12-31T23:59:00Z"
      }
    }
  }'

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:

{
  "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", "..." ]
  }
}
🚀
date breakdown query
filter
read more
Try it on Postman