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.
{"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" }}
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.
// Define queryvar query = {"embedAssets":true};// Stringify and URI Encode the Objectquery =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) { returnresponse.json() }).then(function (data) {console.log(data) })
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.
{"fields": {"title":"Hello World!","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" } } ] }}
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.