Last returns shipped from a specific country

POST https://{{subdomain}}.commercelayer.io/metrics/returns/search

The problem

Among the ones requested for your orders, you want to get the last returns that were shipped back from a specific country, over a selected date and time range, chronologically ordered by date of creation. For each return, you want to get all the available information.

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:

KeyValue
limit10
sort_byreturn.created_at
fields[ "return.\\\\*" ]

Remember to use the .\\\\* syntax to get in the search results all the attributes of the return field for each record (read more about this).

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 return field to restrict the related search on returns whose lifecycle is beyond shipping only:

AttributeOperator
statuses"in": [ "shipped", "received" ]

Add an additional filter on the origin address field to restrict the related search on returns that were shipped from the selected country only:

AttributeOperator
country_codes"in": [ "US" ]

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"=>"return.created_at", "fields"=>["return.*"]}, "filter"=>{"return"=>{"date_from"=>"{{date_from}}", "date_to"=>"{{date_to}}", "statuses"=>{"in"=>["shipped", "received"]}}, "origin_address"=>{"country_codes"=>{"in"=>["{{country_1}}"]}}}}

HEADERS

KeyDatatypeRequiredDescription
Acceptstring
Content-Typestring