Collections

Fetching Collections

This demonstrates a basic query for a collection.

All examples can be used with/documents Endpoint as well.

window.fetch('https://api.cmft.io/v1/<repo>/collections/<collection>', {
  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/collections/news?key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck

Query Parameters

Name
Type
Description

key

string

API Key

Response Shaping

Let's say we want to display a news page with a teaser view for each article. To reduce the payload we're going to do a request and tell the API to include only the fields title , text and image for each document.

Sample Request

GET https://api.cmft.io/v1/demo/collections/news?fields=fields(title,text,image)&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck

Path Parameters

Name
Type
Description

key

string

API Key

Reduced scopes

This example query makes a collection request that will only return the meta scope for each document.

Sample Request

GET https://api.cmft.io/v1/demo/collections/news?fields=meta&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck

Path Parameters

Name
Type
Description

key

string

API Key

Reduced fields for relations

This query returns a full list of documents, but for the relations the payload is limited to the fields name and id.

The parameter explained

Sample Request

GET https://api.cmft.io/v1/demo/collections/news?includes=1&fields=includes(news(fields(title),meta(id))),fields,meta

Path Parameters

Name
Type
Description

key

string

API Key

Applying filters to collection queries

You can apply additional filters on all documents in a collection. Find examples with multiple filters on the filters examples page.

Filter by checkbox state

In this example we're going to check the availability of a product based on a simple checkbox field.

Sample Request

GET https://api.cmft.io/v1/demo/collections/products?filters[0][*.fields.inStock][equal]=true&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck

Path Parameters

Name
Type
Description

key

string

API Key

Collection queries with localisation

Lets query a collection in a specific Language

Sample Request

GET https://api.cmft.io/v1/demo/collections/news?locale=en&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck

Path Parameters

Name
Type
Description

key

string

API Key

Query all Languages

Sample Request

GET https://api.cmft.io/v1/demo/collections/news?locale=all&key=8MIO994Ley6bqyAlQAHqutiDh4g5Heck

Path Parameters

Name
Type
Description

key

string

API Key

Last updated