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.
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)
})
Sample Request
GET
https://api.cmft.io/v1/demo/documents?includes=1&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck
Query Parameters
Name | Type | Description |
---|---|---|
key | string | API Key |
{
"status": 200,
"meta": {
"count": 5,
"limit": 25,
"offset": 0,
"total": 5
},
"data": [
{
"fields": {
"title": "Christian Schwerdt",
"shorthand": "CS"
},
"meta": {
"id": "968388973430968320",
"contentType": "author",
"repository": "968388392691830784",
"revision": 1,
"tags": [],
"createdAt": "2018-07-06T12:58:43.000Z",
"updatedAt": "2018-07-06T12:58:43.000Z"
}
},
{
"fields": {
"title": "Hello World!",
"date": "2018-07-06T13:00:00.000Z",
"text": {
"html": "<p>Lorem ipsum dolor sit amet, consetetur <strong>sadipscing elitr, sed diam</strong> nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.</p>",
"plain": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod\ntempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At\nvero eos et accusam et justo duo dolores et ea rebum."
},
"images": [
{
"meta": {
"id": "968393840635547648",
"contentType": "_asset"
}
}
],
"relatedNews": [],
"author": [
{
"meta": {
"id": "968388973430968320",
"contentType": "author"
}
}
]
},
"meta": {
"id": "968390655497867264",
"contentType": "news",
"repository": "968388392691830784",
"revision": 5,
"tags": [],
"createdAt": "2018-07-06T13:05:24.000Z",
"updatedAt": "2018-07-06T13:23:08.000Z"
}
},
{
"fields": {
"title": "Simple Blog Post",
"date": "2018-07-04T22:00:00.000Z",
"text": {
"html": "<h1>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.</h1>",
"plain": "LOREM IPSUM DOLOR SIT AMET, CONSETETUR SADIPSCING ELITR, SED DIAM NONUMY EIRMOD\nTEMPOR INVIDUNT UT LABORE ET DOLORE MAGNA ALIQUYAM ERAT, SED DIAM VOLUPTUA. AT\nVERO EOS ET ACCUSAM ET JUSTO DUO DOLORES ET EA REBUM."
},
"images": [
{
"meta": {
"id": "968393848009134080",
"contentType": "_asset"
}
}
],
"relatedNews": [
{
"meta": {
"id": "968390655497867264",
"contentType": "news"
}
}
],
"author": [
{
"meta": {
"id": "968388973430968320",
"contentType": "author"
}
}
]
},
"meta": {
"id": "968395804664537088",
"contentType": "news",
"repository": "968388392691830784",
"revision": 1,
"tags": [],
"createdAt": "2018-07-06T13:25:51.000Z",
"updatedAt": "2018-07-06T13:25:51.000Z"
}
},
{
"fields": {
"title": "Beautiful Bicycle",
"description": {
"html": "<p>Aluminium Frame; Disc Brakes; Shimano XTR;</p>",
"plain": "Aluminium Frame; Disc Brakes; Shimano XTR;"
},
"price": 1399,
"relatedProducts": [],
"rating": "5",
"inStock": true,
"images": [
{
"meta": {
"id": "969465200912769024",
"contentType": "_asset"
}
}
]
},
"meta": {
"id": "969464870959452160",
"contentType": "products",
"repository": "968388392691830784",
"revision": 4,
"tags": [],
"createdAt": "2018-07-09T12:13:57.000Z",
"updatedAt": "2018-07-09T12:30:01.000Z"
}
},
{
"fields": {
"title": "Nice Bicycle",
"description": {
"html": "<p>Aluminium Frame; Disc Brakes; Shimano XT;</p>",
"plain": "Aluminium Frame; Disc Brakes; Shimano XT;"
},
"price": 1399,
"relatedProducts": [],
"rating": "3",
"inStock": false,
"images": [
{
"meta": {
"id": "969465200912769024",
"contentType": "_asset"
}
}
]
},
"meta": {
"id": "969468642649575424",
"contentType": "products",
"repository": "968388392691830784",
"revision": 2,
"tags": [],
"createdAt": "2018-07-09T12:28:56.000Z",
"updatedAt": "2018-07-09T12:29:23.000Z"
}
}
],
"includes": {
"author": [
{
"fields": {
"title": "Christian Schwerdt",
"shorthand": "CS"
},
"meta": {
"id": "968388973430968320",
"contentType": "author",
"repository": "968388392691830784",
"revision": 1,
"tags": [],
"createdAt": "2018-07-06T12:58:43.000Z",
"updatedAt": "2018-07-06T12:58:43.000Z"
}
}
],
"news": [
{
"fields": {
"title": "Hello World!",
"date": "2018-07-06T13:00:00.000Z",
"text": {
"html": "<p>Lorem ipsum dolor sit amet, consetetur <strong>sadipscing elitr, sed diam</strong> nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.</p>",
"plain": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod\ntempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At\nvero eos et accusam et justo duo dolores et ea rebum."
},
"images": [
{
"meta": {
"id": "968393840635547648",
"contentType": "_asset"
}
}
],
"relatedNews": [],
"author": [
{
"meta": {
"id": "968388973430968320",
"contentType": "author"
}
}
]
},
"meta": {
"id": "968390655497867264",
"contentType": "news",
"repository": "968388392691830784",
"revision": 5,
"tags": [],
"createdAt": "2018-07-06T13:05:24.000Z",
"updatedAt": "2018-07-06T13:23:08.000Z"
}
}
],
"_asset": [
{
"fields": {
"title": "picture-01.jpg",
"description": "",
"file": {
"ext": "jpg",
"path": "968388392691830784/968393840635547648/968393840656523264/picture-01.jpg",
"size": 87129,
"filename": "picture-01.jpg",
"mimetype": "image/jpeg",
"createdAt": "2018-07-06T13:18:03.000Z",
"dimensions": {
"width": 1920,
"height": 1080
},
"originalFile": {
"name": "picture-01.jpg",
"size": 87129,
"type": "image/jpeg"
},
"url": "https://images.cmft.io/968388392691830784/968393840635547648/968393840656523264/picture-01.jpg"
}
},
"meta": {
"id": "968393840635547648",
"contentType": "_asset",
"repository": "968388392691830784",
"revision": 1,
"tags": [],
"createdAt": "2018-07-06T13:18:03.000Z",
"updatedAt": "2018-07-06T13:18:03.000Z"
}
},
{
"fields": {
"title": "picture-04.jpg",
"description": "",
"file": {
"ext": "jpg",
"path": "968388392691830784/968393848009134080/968393848034304000/picture-04.jpg",
"size": 96972,
"filename": "picture-04.jpg",
"mimetype": "image/jpeg",
"createdAt": "2018-07-06T13:18:03.000Z",
"dimensions": {
"width": 1920,
"height": 1080
},
"originalFile": {
"name": "picture-04.jpg",
"size": 96972,
"type": "image/jpeg"
},
"url": "https://images.cmft.io/968388392691830784/968393848009134080/968393848034304000/picture-04.jpg"
}
},
"meta": {
"id": "968393848009134080",
"contentType": "_asset",
"repository": "968388392691830784",
"revision": 1,
"tags": [],
"createdAt": "2018-07-06T13:18:05.000Z",
"updatedAt": "2018-07-06T13:18:05.000Z"
}
},
{
"fields": {
"title": "photo-1507035895480-2b3156c31fc8",
"description": "",
"file": {
"ext": "jpg",
"path": "968388392691830784/969465200912769024/969465200933740544/photo-1507035895480-2b3156c31fc8",
"size": 1171067,
"filename": "photo-1507035895480-2b3156c31fc8",
"mimetype": "image/jpeg",
"createdAt": "2018-07-09T12:15:14.000Z",
"dimensions": {
"width": 4758,
"height": 3172
},
"originalFile": {
"name": "photo-1507035895480-2b3156c31fc8",
"size": 1171067,
"type": "image/jpeg"
},
"url": "https://images.cmft.io/968388392691830784/969465200912769024/969465200933740544/photo-1507035895480-2b3156c31fc8"
}
},
"meta": {
"id": "969465200912769024",
"contentType": "_asset",
"repository": "968388392691830784",
"revision": 1,
"tags": [],
"createdAt": "2018-07-09T12:15:15.000Z",
"updatedAt": "2018-07-09T12:15:15.000Z"
}
}
]
}
}
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
.
// 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
Sample Request
GET
https://api.cmft.io/v1/demo/documents?includes[news.fields.author]=1&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck
Path Parameters
Name | Type | Description |
---|---|---|
key | string | API Key |
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.
// 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
Sample Request (TODO)
GET
Path Parameters
Name | Type | Description |
---|---|---|
key | string | API Key |
Last updated