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:

StatDescription
countThe total number of orders for which a return containing more than one SKU was requested.
minThe minimum number of SKUs included in a return.
maxThe maximum number of SKUs included in a return.
avgThe average number of SKUs included in a return.
sumThe 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:

KeyValue
fieldreturn.skus_count
operatorstats

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:

AttributeOperator
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

KeyDatatypeRequiredDescription
Acceptstring
Content-Typestring