Content API

Languages

When internationalisation is switched on in your site settings, you can request content in each language you have defined.

Setting the language on a request

To return content in a specific language you need to set the language on the request by setting the X-CONTENTO-LANGUAGE header to the language identifier you wish to get content in.

For example, if our primary language is en but we have a second language of fr, then by default the API will only return content in en so to request content in fallback_default_languagefr we have to set X-CONTENTO-LANGUAGE to fr.

Example:

GET https://app.contento.io/api/v1/content HTTP/1.1
Authorization: Bearer {token}
X-CONTENTO-SITE: {site_id}
X-CONTENTO-LANGUAGE: en-US

Mixing in missing translations

In some scenarios you might have less content available in one language than the other. By default, the API will only ever return content in the language you have requested - regardless of if there is less content in the chosen language than in the primary language dataset.

To change this behaviour you can set the fallback_default_language query parameter to true and the API will mix in results from the primary language where needed. For example this can be useful if you have written all your blog posts in English, but have only translated a few to French. Rather than only display a small list of translated posts you can display the full list, with the missing translations shown in English.

Content ID and language mis-match

In the /content/{id} API endpoint if you send a request for a content record that is not in the same language as that specified in the X-CONTENTO-LANGUAGE header the API will return the child content that matches the requested language if there is one.

For example if we have the following setup:

  • en: c_english_id
  • fr: c_french_id, child of c_english_id

We can send a request to /content/c_english_id with X-CONTENTO-LANGUAGE = fr and the API will return c_french_id. This is useful if you don’t know if a translated version of page exists or not as the API will look it up for you and return it if possible.

Previous
Pagination