Links
Comment on page

Includes

Include relations by level

This query returns all of the related documents for the first level of a collection for a football team, footballTeams. The content type footballTeam has a relations field to link the players.
URL
CURL
JavaScript
https://api.cmft.io/v1/<repo>/footballTeams?key=<apiKey>&includes=1
curl 'https://api.cmft.io/v1/<repo>/footballTeams?includes=1' \
-H 'Authorization: <apiKey>'
// Define query
let query = {
"includes": 1
};
// Stringify and URI Encode the Object
query = encodeURIComponent(JSON.stringify(query));
// Submit the query
window.fetch(`https://api.cmft.io/v1/<repo>/footballTeams?query=${query}`, {
method: 'get',
headers: {
'Content-Type': 'application/json',
'Authorization': '<apiKey>'
}
})
.then(function (response) { return response.json() })
.then(function (data) {
console.log(data)
})
get
https://api.cmft.io
/v1/demo/documents?includes=1&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck
Sample Request

Include relations from specific fields

If the content type footballTeam had more than one relation field, e.g. for its trainers or a city, we would query the relations only for the field players.
JavaScript
CURL
URL
// Define query
var query = {
"includes": {
"*.fields.players": 1
}
};
// Stringify and URI Encode the Object
query = encodeURIComponent(JSON.stringify(query));
// Submit the query
window.fetch(`https://api.cmft.io/v1/<repo>/footballTeams?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>/footballTeams?includes[*.fields.players]=1' \
-H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/footballTeams?key=<apiKey>&includes[*.fields.players]=1
get
https://api.cmft.io
/v1/demo/documents?includes[news.fields.author]=1&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck
Sample Request

Including Assets in Documents

There is a easy way to have assets shipped within a field of a document, if you don't want to collect it from includes.
You can do this for collections or single documents. In the following example we'll fetch a collection of football players and want to have their pictures included within the document. This makes iterating the list, e.g. for a list template, much more comfortable.
JavaScript
CURL
URL
// Define query
var query = {
"embedAssets": true
};
// Stringify and URI Encode the Object
query = encodeURIComponent(JSON.stringify(query));
// Submit the query
window.fetch(`https://api.cmft.io/v1/<repo>/footballPlayers?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>/footballPlayers?embedAssets=true \
-H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/footballPlayers?key=<apiKey>&embedAssets=true
get
Sample Request (TODO)