Mixed stats about returns that contain more than one product
POST https://{{subdomain}}.commercelayer.io/metrics/returns/stats
The problem
Among the ones containing more that one products, you want to get some common statistics about the number of SKUs present in the returns requested from your orders, over a selected date and time range. Specifically:
Stat | Description |
---|---|
count | The total number of orders for which a return containing more than one SKU was requested. |
min | The minimum number of SKUs included in a return. |
max | The maximum number of SKUs included in a return. |
avg | The average number of SKUs included in a return. |
sum | The sum of all the SKUs included in the returns containing more than one SKU. |
The solution
Query
You need to perform a stats query setting the required query keys as follows:
Key | Value |
---|---|
field | return.skus_count |
operator | stats |
Make sure to set the desired date and time range using the date_from
and date_to
keys or as your environment variables and add an additional filter on the return field to restrict the related search on returns containing more than one SKU only:
Attribute | Operator |
---|---|
skus_count | "gt": 1 |
In this example, since we use created_at
as the date_field
, you'll get in the response all the returns that were created within the selected date and time range ([read more] this).
Request Body
{"stats"=>{"field"=>"return.skus_count", "operator"=>"stats"}, "filter"=>{"return"=>{"date_from"=>"{{date_from}}", "date_to"=>"{{date_to}}", "date_field"=>"created_at", "skus_count"=>{"gt"=>1}}}}
HEADERS
Key | Datatype | Required | Description |
---|---|---|---|
Accept | string | ||
Content-Type | string |