You can easily sort results that are returned from the API. For example you could make the following request to get all products and sort them by the created_at timestamp.

Sorting is only available on the get all products endpoint.

Sort products by created_at ASC

cURL
JavaScript SDK
Swift SDK
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
})
let moltin = Moltin(withClientID: "<your client ID>")
moltin.product.sort("created_at").all {
// Do something
}

Sort products by created_at DESC

To reverse the sort order, you must prepend a minus.

cURL
JavaScript SDK
Swift SDK
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
})
let moltin = Moltin(withClientID: "<your client ID>")
moltin.product.sort("-created_at").all {
// Do something
}