Total number of returns per year and average number of products included by destination city
POST https://{{subdomain}}.commercelayer.io/metrics/returns/date_breakdown
The problem
You want to get the total number of returns requested for your orders, over a selected date and time range, grouped by year. For each year, you also want to group the results by the city where the stock location to which the items were returned is located and know the average number of SKUs the were included in the returns.
The solution
Query
You need to perform a date breakdown query setting the required query keys as follows and adding the optional ones based on your needs:
Key | Value |
---|---|
by | return.current_date |
field | return.id |
operator | value_count |
interval | year |
Change the interval
key if you want to group the results differently (e.g. by day
or hour
— default is month
).
You also need to add a nested breakdown setting the related query keys as follows:
Key | Value |
---|---|
by | destination_address.city |
field | return.skus_count |
operator | avg |
Filter
Make sure to set the desired date and time range using the date_from
and date_to
keys in the filter or as your environment variables.
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 returns that actually changed their status each day within the selected date and time range (read more about this).
Request Body
{"date_breakdown"=>{"by"=>"return.current_date", "field"=>"return.id", "operator"=>"value_count", "interval"=>"year", "breakdown"=>{"by"=>"destination_address.city", "field"=>"return.skus_count", "operator"=>"avg"}}, "filter"=>{"return"=>{"date_from"=>"{{date_from}}", "date_to"=>"{{date_to}}"}}}
HEADERS
Key | Datatype | Required | Description |
---|---|---|---|
Accept | string | ||
Content-Type | string |