Links

Single Documents

Basic document query

Demonstrates how to query a single document.

Query by Document ID

JavaScript
CURL
URL
window.fetch('https://api.cmft.io/v1/<repo>/documents/<documentID>', {
method: 'get',
headers: {
'Content-Type': 'application/json',
'Authorization': '<apiKey>'
}
})
.then(function (response) { return response.json() })
.then(function (data) {
console.log(data)
})
curl 'https://api.cmft.io/v1/<repo>/documents/<documentID>' \
-H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/documents/<documentID>?key=<apiKey>

Query by Document Alias

You can create an alias for a single document by linking it in the Content Tree. Once an alias is created, it is possible to switch out the document that's connected to that alias.
JavaScript
CURL
URL
window.fetch('https://api.cmft.io/v1/<repo>/alias/<myAliasName>', {
method: 'get',
headers: {
'Content-Type': 'application/json',
'Authorization': '<apiKey>'
}
})
.then(function (response) { return response.json() })
.then(function (data) {
console.log(data)
})
curl 'https://api.cmft.io/v1/<repo>/alias/<myAliasName>' \
-H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/alias/<myAliasName>?key=<apiKey>
get
https://api.cmft.io
/v1/demo/documents/968390655497867264?key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck
Sample Request by ID

Including Assets for Documents

When querying documents, add embedAssets=true as URL parameter or as a query option to include assets by default, within a documents fields. This eliminates the need to perform single asset queries and reduces the number of API calls.
embedAssets works for single documents and document lists as well.
JavaScript
CURL
URL
// Define query
var query = {
"embedAssets": true
};
// Stringify and URI Encode the Object
query = encodeURIComponent(JSON.stringify(query));
window.fetch(`https://api.cmft.io/v1/<repo>/documents/<documentID>?query=${query}`, {
method: 'get',
headers: {
'Content-Type': 'application/json',
'Authorization': '<apiKey>'
}
})
.then(function (response) { return response.json() })
.then(function (data) {
console.log(data)
})
curl 'https://api.cmft.io/v1/<repo>/documents/<documentID>&embedAssets=true' \
-H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/documents/<documentID>?embedAssets=true&key=<apiKey>
get
https://api.cmft.io
/v1/demo/documents/968390655497867264?embedAssets=true&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck
Sample Request with Assets included

Response Shaping: Document query with reduced fields

Let's say we need a document, but not all of its content. In this query example we're going to request a document only with the fields title, text and image.
To learn more about defined fields, take a look at the fields query reference page.
JavaScript
CURL
URL
// Define query
var query = {
"fields": "fields(title,text,image)"
};
// Stringify and URI Encode the Object
query = encodeURIComponent(JSON.stringify(query));
window.fetch(`https://api.cmft.io/v1/<repo>/documents/<documentID>?query=${query}`, {
method: 'get',
headers: {
'Content-Type': 'application/json',
'Authorization': '<apiKey>'
}
})
.then(function (response) { return response.json() })
.then(function (data) {
console.log(data)
})
curl 'https://api.cmft.io/v1/<repo>/documents/<documentID>&fields=fields(title,text,images)' \
-H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/documents/<documentID>?fields=fields(title,text,images)&key=<apiKey>
get
https://api.cmft.io
/v1/demo/documents/968390655497867264?fields=fields(title,text,images)&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck
Sample Request

Document query with localisation

Example for requesting a document in one specific language (German). This will return all fields that have translation enabled and completed, in German.
JavaScript
CURL
URL
window.fetch('https://api.cmft.io/v1/<repo>/documents/<documentID>?locale=de', {
method: 'get',
headers: {
'Content-Type': 'application/json',
'Authorization': '<apiKey>'
}
})
.then(function (response) { return response.json() })
.then(function (data) {
console.log(data)
})
curl 'https://api.cmft.io/v1/<repo>/documents/<documentID>&locale=de' \
-H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/documents/<documentID>?key=<apiKey>&locale=de