Total number of pending carts by customer email and payment method name

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

The problem

You want to get the total number of carts over a selected date and time range, grouped by their associated customer. For each customer, you also want to group the results by the related payment method.

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
bycustomer.email
fieldorder.id
operatorvalue_count

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

KeyValue
bypayment_method.name
fieldorder.id
operatorvalue_count

Filter

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 order field to restrict the related computation to pending carts only:

AttributeOperator
statuses"in": [ "pending" ]

In this example, since we use updated_at as the date_field, only the orders that were updated within the selected date and time range will be considered for the stats computation (read more about this).

Request Body

{"breakdown"=>{"by"=>"customer.email", "field"=>"order.id", "operator"=>"value_count", "sort"=>"desc", "limit"=>30, "breakdown"=>{"by"=>"payment_method.name", "field"=>"order.id", "operator"=>"value_count", "sort"=>"desc", "limit"=>10}}, "filter"=>{"order"=>{"date_from"=>"{{date_from}}", "date_to"=>"{{date_to}}", "date_field"=>"updated_at", "statuses"=>{"in"=>["pending"]}}}}

HEADERS

KeyDatatypeRequiredDescription
Acceptstring
Content-Typestring