Total number of pending carts with amount greater than 100€

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

The problem

You want to get the total number of pending (e.g. potentially abandoned) carts whose total amount (with taxes) is greater than 100€, over a selected date and time range.

The solution

Query

You need to perform a stats query setting the required query keys as follows:

KeyValue
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 additional filters on the order field to restrict the related computation to the desired carts only:

AttributeOperator
statuses"in": [ "pending" ]
currency_codes"in": [ "EUR" ]
total_amount_with_taxes"gt": 100

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

{"stats"=>{"field"=>"order.id", "operator"=>"value_count"}, "filter"=>{"order"=>{"date_from"=>"{{date_from}}", "date_to"=>"{{date_to}}", "date_field"=>"updated_at", "statuses"=>{"in"=>["pending"]}, "currency_codes"=>{"in"=>["EUR"]}, "total_amount_with_taxes"=>{"gt"=>100}}}}

HEADERS

KeyDatatypeRequiredDescription
Acceptstring
Content-Typestring