Comfortable | Docs
  • Comfortable Documentation
  • Concepts
    • Content Repositories
    • Content Types
    • Documents
    • Assets
    • Content Tree
    • Collections
    • Webhooks
    • Team
    • Locales
  • APIs
    • RESTful API
      • Endpoints
      • API Reference
        • Sorting
        • Filters
        • Localisation
        • Fields
        • Includes
        • Search
      • Query Examples
        • Collections
        • Single Documents
        • Single Assets
        • Sorting
        • Filters
        • Includes
    • Image Manipulation
  • SDKs
    • JavaScript
      • Query Options
      • Query All Documents
      • Query a Collection
      • Query a Single Document
      • Query an Alias
      • Query an Asset
      • Example: Filters
      • Example: Sorting
    • Nuxt.js
    • PHP
      • Query All Documents
      • Query Single Document
      • Query Collection
      • Query an Alias
      • Query an Asset
      • Fulltext Search
      • Query by Fields
      • Query by Type
      • Query by Id
      • Query by Tags
  • Guides
    • Vue Blog Example
  • Legal
    • Legal Notice
    • Privacy Policy
Powered by GitBook
On this page
  • Basic asset query
  • Response Shaping: Asset query with reduced fields
  • Asset query with localisation
  1. APIs
  2. RESTful API
  3. Query Examples

Single Assets

PreviousSingle DocumentsNextSorting

Last updated 6 years ago

Basic asset query

Demonstrates the basic query for a single asset.

window.fetch('https://api.cmft.io/v1/<repo>/assets/<assetID>', {
  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>/assets/<assetID>' \
  -H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/assets/<assetID>?key=<apiKey>

When querying documents, addembedAssets=true as URL parameter or as a query option to include assets by default. This eliminates the need to perform single asset queries and reduces the number of API calls.

Response Shaping: Asset query with reduced fields

Like documents, assets have fields which can be defined when making a query. In this example, we're going to query an asset just with its target URL.

To learn how to make a request with multiple fields, take a look at the .

window.fetch('https://api.cmft.io/v1/<repo>/assets/<assetID>?fields=fields(file(url))', {
  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>/assets/<assetID>?fields=fields(file(url))' \
  -H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/assets/<assetID>?key=<apiKey>&fields=fields(file(url))

Asset query with localisation

Example for requesting an asset in one specific language (German).

window.fetch('https://api.cmft.io/v1/<repo>/assets/<assetID>?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>/assets/<assetID>?locale=de' \
  -H 'Authorization: <apiKey>'
https://api.cmft.io/v1/<repo>/assets/<assetID>?key=<apiKey>&locale=de
fields query reference page
See example