Last created carts containing a specific SKU and associated with a specific market
POST https://{{subdomain}}.commercelayer.io/metrics/carts/search
The problem
You want to get the last created carts that contain a specific product and are associated with a specific market, over a selected date and time range, chronologically ordered by date of creation.
The solution
Query
You need to perform a search query setting the required query keys as follows and adding the optional ones based on your needs:
| Key | Value |
|---|---|
limit | 10 |
sort_by | order.created_at |
If you want to focus on some specific information about the carts you're searching for, just fill in the fields array with the list of attributes you want to get in the response.
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
Add an additional filter on the line items field to restrict the related search on carts that contain the selected SKU only:
| Attribute | Operator |
|---|---|
codes | "in": [ "TSHIRT0001" ] |
Add an additional filter on the market field to restrict the related search on the carts associated with the selected market only:
| Attribute | Operator |
|---|---|
names | "in": [ "North America" ] |
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 returns that changed their status within the selected date and time range (read more about this).
Request Body
{"search"=>{"limit"=>10, "sort"=>"desc", "sort_by"=>"order.created_at", "fields"=>["order.created_at", "order.status", "order.total_amount_with_taxes", "customer.email", "market.*", "line_items.*"]}, "filter"=>{"order"=>{"date_from"=>"{{date_from}}", "date_to"=>"{{date_to}}"}, "line_items"=>{"codes"=>{"in"=>["{{sku_1}}"]}}, "market"=>{"names"=>{"in"=>["{{market_1}}"]}}}}
HEADERS
| Key | Datatype | Required | Description |
|---|---|---|---|
Accept | string | ||
Content-Type | string |