Sorting
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:
warning
You can not sort by created_at
or updated_at
if you are using filtering.
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 -X GET https://api.moltin.com/v2/products?sort=created_at
-H "Authorization: Bearer XXXX"
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X'
})
Moltin.Products.All()
.Sort('created_at')
.then(products => {
// Do something
})
created_at
in descending order
Sort products by curl -X GET https://api.moltin.com/v2/products?sort=-created_at
-H "Authorization: Bearer XXXX"
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X'
})
Moltin.Products.All()
.Sort('-created_at')
.then(products => {
// Do something
})