Content API

Endpoints

Support for other resources

At the moment you can only fetch content objects via this API, in the future we will add more endpoints to support content types and assets.

Content

Content is the core resource you will need to fetch using the API. Read the content object reference for a full breakdown of how they are returned in an API response.

Available endpoints

Retrieve a content object

Retrieves a published content object. Supply the content ID that you were given in a previous request or have copied from the Contento admin panel.

Request

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

Response

A content object with timestamps.

{
  "id": "RaDf2yMpL6",
  "published_at": "2022-09-27T08:54:06+00:00",
  "slug": "vertical-saas",
  "name": "The Growth of Vertical SaaS",
  "author": {
    ...
  },
  "content_type": {
    ...
  },
  "fields": {
    ...
  },
  "created_at": "2022-09-15T13:39:40+00:00",
  "updated_at": "2022-09-27T08:59:39+00:00"
}

List all content

Returns a paginated list of published content. The content objects are sorted in the list with the most recently published appearing first.

Request

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

Parameters

Query parameters can be appended to the request url to filter, limit or sort the results.

In most cases you can supply either one instance of a parameter with a single value (e.g. ?content_type=blog_post), or supply multiple values using the array syntax (e.g. ?content_type[0]=blog_post&content_type[1]=case_study). If you do send multiple values then they will be executed as an AND query.

ParameterFormatsDefaultAccepted values
authorString or ArrayID of the author(s) you want to filter by.
content_typeString or ArrayHandle of the content type you want to filter by.
content_type_idString or ArrayID of the content type you want to filter by.
cursorStringCursor for pagination.
limitInteger20The number of results you want in the response.
slugString or ArraySlug of the specific content object you want to retrieve.
sortString or Arraypublished_at:descYou must supply values in the following format: attribute:directionread more.

Sorting the query

The sort attribute can take either fixed attributes that always on every content object, or certain fields. The fixed attributes supported are as follows:

  • published_at
  • created_at
  • updated_at
  • name
  • slug
  • uri

This must be followed by a sort direction of desc or asc in the following format: attribute:direction. So, to sort by name ascending you would supply name:asc.

You may also supply certain fields instead of one of the fixed attributes. The supported field types at the moment are text or integer fields. You must construct your attribute like so: field_handle.value_accessor:direction.

For a text field that might look like the following: post_title.text:asc. An integer field might look like this: popularity.number:desc.

Please bear in mind that whilst sorting by field values will work across content types, its most useful when all the content in the request has the same field available to do the sorting on. If you mix content types and some have the field and others don’t, then the API will fall back to sorting by id after the field sort runs. This can lead to some confusing results, so ideally filter your requests by content_type as well.

Response

This will contain an array of content objects and associated pagination data.

AttributeTypeDescription
dataArraySorted array of content objects or an empty array if nothing can be found.
linksObjectA links pagination object.
metaObjectA meta pagination object.
{
  "data": [
    {
      "id": "RaDf2yMpL6",
      "published_at": "2022-09-27T08:54:06+00:00",
      "slug": "vertical-saas",
      "name": "The Growth of Vertical SaaS",
      "author": {
        ...
      },
      "content_type": {
        ...
      },
      "fields": {
        ...
      },
      "created_at": "2022-09-15T13:39:40+00:00",
      "updated_at": "2022-09-27T08:59:39+00:00"
    },
    ...
  ],
  "links": {
    "first": null,
    "last": null,
    "prev": null,
    "next": "https://app.contento.io/api/v1/content?cursor=eyJwdWJsaXNoZWRfYXQiOiIyMDIyLTA2LTA3IDExOjU0OjMwIiwiX3BvaW50c1RvTmV4dEl0ZW1zIjp0cnVlfQ"
  },
  "meta": {
    "path": "https://app.contento.io/api/v1/content",
    "per_page": 20,
    "next_cursor": "eyJwdWJsaXNoZWRfYXQiOiIyMDIyLTA2LTA3IDExOjU0OjMwIiwiX3BvaW50c1RvTmV4dEl0ZW1zIjp0cnVlfQ",
    "prev_cursor": null
  }
}
Previous
Object Reference