Sorting
note
This applies to V2 endpoints only.
Sort results that are returned from the API by using the sort
parameter with the field name you want to sort against.
note
To reverse the sort order, prepend the field with a minus.
Currently, sorting is supported for the following endpoints, and against the following fields:
Endpoint | Fields to sort against |
---|---|
Brands | created_at , description , name , slug , status , updated_at |
Categories | created_at , description , name , slug , status , updated_at |
Collections | created_at , description , name , slug , status , updated_at |
Products | commodity_type , created_at , description , manage_stock , name , sku ,slug , status , updated_at |
Product Variations | name |
Orders | created_at , payment , shipping , status , with_tax |
The following example shows how to make a request to get all products, and sort them by the created_at
timestamp.
created_at
in ascending order
Sort products by Curl
curl -X GET https://api.moltin.com/v2/products?sort=created_at
-H "Authorization: Bearer XXXX"
JavaScript SDK
// Where `EPCC` is an authenticated client
await EPCC.Products.All().Sort("created_at");
created_at
in descending order
Sort products by Curl
curl -X GET https://api.moltin.com/v2/products?sort=-created_at
-H "Authorization: Bearer XXXX"
JavaScript SDK
// Where `EPCC` is an authenticated client
await EPCC.Products.All().Sort("-created_at");