Links

Sorting

Order response by creation date

Query a collection and order the results ascending by creation date.
JavaScript
CURL
URL
GET
// Define query
var query = {
"sorting": {
"meta.createdAt": "ASC"
}
};
// Stringify and URI Encode the Object
query = encodeURIComponent(JSON.stringify(query));
// Submit the query
window.fetch(`https://api.cmft.io/v1/<repo>/<collection>?query=${query}`, {
method: 'get',
headers: {
'Content-Type': 'application/json',
'Authorization': '<apiKey>'
}
})
.then(function (response) { return response.json() })
.then(function (data) {
console.log(data)
})
curl -g 'https://api.cmft.io/v1/<repo>/<collection>?sorting[meta.createdAt]=ASC' \
-H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/<collection>?key=<apiKey>&sorting[meta.createdAt]=ASC

Order response by field value

Query the documents endpoint and order the results ascending by title.
JavaScript
CURL
URL
// Define query
var query = {
"sorting": {
"fields.title": "ASC"
}
};
// Stringify and URI Encode the Object
query = encodeURIComponent(JSON.stringify(query));
// Submit the query
window.fetch(`https://api.cmft.io/v1/<repo>/documents?query=${query}`, {
method: 'get',
headers: {
'Content-Type': 'application/json',
'Authorization': '<apiKey>'
}
})
.then(function (response) { return response.json() })
.then(function (data) {
console.log(data)
})
curl -g 'https://api.cmft.io/v1/<repo>/documents?sorting[fields.title]=ASC' \
-H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/documents?key=<apiKey>&sorting[fields.title]=ASC
get
https://api.cmft.io
/v1/demo/documents?sorting[fields.title]=ASC&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck
Sample Request

Using multiple sorting parameters

You can apply multiple order parameters:
JavaScript
CURL
URL
// Define query
var query = {
"sorting": {
"fields.title": 'ASC',
"meta.createdAt": 'DESC'
}
};
// Stringify and URI Encode the Object
query = encodeURIComponent(JSON.stringify(query));
// Submit the query
window.fetch(`https://api.cmft.io/v1/<repo>/documents?query=${query}`, {
method: 'get',
headers: {
'Content-Type': 'application/json',
'Authorization': '<apiKey>'
}
})
.then(function (response) { return response.json() })
.then(function (data) {
console.log(data)
})
curl -g 'https://api.cmft.io/v1/<repo>/documents?sorting[fields.title]=ASC&sorting[meta.createdAt]=DESC' \
-H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/documents?key=<apiKey>&sorting[fields.title]=ASC&sorting[meta.createdAt]=DESC
get
https://api.cmft.io
/v1/demo/documents?sorting[fields.title]=ASC&sorting[meta.createdAt]=DESC&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck
Sample Request