Links

Queries

All the available Commerce Layer Metrics API query types and the supported operators
Commerce Layer Metrics API lets you retrieve metric data and statistics through four types of queries:
Breakdown, date breakdown, and stats queries return aggregated metrics computed on the values of specific fields, based on selected operators. The search query is an actual search, returning the specified fields of the matching records.
The examples in the following pages will be focused on the query part of the request. The orders endpoint will be used as a reference and no specific filter or meta options will be defined (i.e. all the results will be filtered by the default filter and the response won't include the request payload). See the use cases section for more complex combinations of queries and filters.

Query operators

To perform breakdown, date breakdown, and stats queries you need to specify the operator you want to use to compute the calculation on the selected field. The valid operators depend on the field itself, hence on the resource you're doing statistics on. You can find here below the complete list of the available operators for the Metrics API queries (see the related tables to check the subset of valid operators by field for orders, returns, or carts).
Operator
Computed value type
Description
avg
Float
A single-value metrics aggregation that computes the average of numeric values extracted from specific numeric fields of the aggregated records.
cardinality
Integer
A single-value metrics aggregation that calculates an approximate count of distinct values.
max
Float
A single-value metrics aggregation that keeps track and returns the maximum value among the numeric values extracted from specific numeric fields of the aggregated records.
min
Float
A single-value metrics aggregation that keeps track and returns the minimum value among the numeric values extracted from specific numeric fields of the aggregated records.
percentiles
Float
A multi-value metrics aggregation that calculates one or more percentiles (i.e. the point at which a certain percentage of observed values occurs) over numeric values extracted from specific numeric fields of the aggregated records.
stats
Object
A multi-value metrics aggregation that computes stats over numeric values extracted from specific numeric fields of the aggregated records. The stats that are returned consist of: count, min, max, avg, and sum.
sum
Float
A single-value metrics aggregation that sums up numeric values extracted from specific numeric fields of the aggregated records.
value_count
Integer
A single-value metrics aggregation that counts the number of values extracted from specific fields of the aggregated records.