Total number of refunds by country and currency code

POST https://{{subdomain}}.commercelayer.io/metrics/orders/breakdown

The problem

You want to get the total number of refunds associated with your orders over a selected date and time range, grouped by the different countries your organization sells in. For each country, you also want to group the results by currency.

The solution

Query

You need to perform a breakdown query setting the required query keys as follows and adding the optional ones based on your needs:

KeyValue
byorder.country_code
fieldrefunds.id
operatorvalue_count

You also need to add a nested breakdown setting the related query keys as follows:

KeyValue
byorder.currency_code
fieldrefunds.id
operatorvalue_count

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, meaning that you'll get in the response all the orders that changed their status within the selected date and time range (read more about this).

Request Body

{"breakdown"=>{"by"=>"order.country_code", "field"=>"refunds.id", "operator"=>"value_count", "sort"=>"desc", "limit"=>20, "breakdown"=>{"by"=>"order.currency_code", "field"=>"refunds.id", "operator"=>"value_count", "sort"=>"desc", "limit"=>20}}, "filter"=>{"order"=>{"date_from"=>"{{date_from}}", "date_to"=>"{{date_to}}"}}}

HEADERS

KeyDatatypeRequiredDescription
Acceptstring
Content-Typestring