Content API

Pagination

Whenever you request a list of objects you will receive a paginated response.

There are two types of pagination available - by default the API will use cursor pagination, but you can also turn on simple pagination and request specific pages by their page number.

Single object responses

If the response contains only one object then a paginated response will not be returned, instead the entire response will be a single object.

This can happen if you set the limit parameter to 1 or if the resulting dataset based on your query parameters results in a single object.


Cursor pagination (default)

Cursor pagination is faster, and most useful when you just need to get the whole dataset for further processing or simply create a "show more posts" type of experience.

It works by creating an encoded string containing the location and direction that the next paginated query should start from.

The only downside is you can’t know the number of pages in the dataset when you get a response, so if you need to know that then use simple pagination instead.

Request

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

Parameters

All the usual parameters are available with paginated requests, the ones that affect pagination directly are listed here:

ParameterFormatDefaultAccepted values
cursorStringCursor string e.g. eyJwdWJsaXNoZWRfYXQiOiIyMDIyLTA2LTA3IDExOjU0OjI5IiwiX3BvaW50c1RvTmV4dEl0ZW1zIjpmYWxzZX0.
limitInteger20The number of results you want in the response.
sortString or Arraypublished_at:descYou must supply values in the following format: attribute:directionread more.

Response

There will be a top level data key that contains the objects you have requested, and then links and meta keys containing the pagination information.

The whole response will look a little something like this:

{
  "data": [ 
    ...
  ],
  "links": {
    "first": null,
    "last": null,
    "prev": "https://app.contento.io/api/v1/content?cursor=eyJwdWJsaXNoZWRfYXQiOiIyMDIyLTA2LTA3IDExOjU0OjI5IiwiX3BvaW50c1RvTmV4dEl0ZW1zIjpmYWxzZX0",
    "next": "https://app.contento.io/api/v1/content?cursor=eyJwdWJsaXNoZWRfYXQiOiIyMDIyLTA2LTA3IDExOjU0OjI5IiwiX3BvaW50c1RvTmV4dEl0ZW1zIjp0cnVlfQ"
  },
  "meta": {
    "path": "https://app.contento.io/api/v1/content",
    "per_page": 20,
    "next_cursor": "eyJwdWJsaXNoZWRfYXQiOiIyMDIyLTA2LTA3IDExOjU0OjI5IiwiX3BvaW50c1RvTmV4dEl0ZW1zIjp0cnVlfQ",
    "prev_cursor": "eyJwdWJsaXNoZWRfYXQiOiIyMDIyLTA2LTA3IDExOjU0OjI5IiwiX3BvaW50c1RvTmV4dEl0ZW1zIjpmYWxzZX0"
  }
}

Provides an interface for quickly getting the previous or next request in the paginated set. URLs will have their cursor parameter set to the correct value and any other parameters that are present in the request will remain in place.

AttributeTypeDescription
firstnullNot in use.
lastnullNot in use.
prevString or nullURL for the previous request in the paginated set.
nextString or nullURL for the next request in the paginated set.

Example:

{
  "first": null,
  "last": null,
  "prev": "https://app.contento.io/api/v1/content?cursor=eyJwdWJsaXNoZWRfYXQiOiIyMDIyLTA2LTA3IDExOjU0OjI5IiwiX3BvaW50c1RvTmV4dEl0ZW1zIjpmYWxzZX0",
  "next": "https://app.contento.io/api/v1/content?cursor=eyJwdWJsaXNoZWRfYXQiOiIyMDIyLTA2LTA3IDExOjU0OjI5IiwiX3BvaW50c1RvTmV4dEl0ZW1zIjp0cnVlfQ"
}

meta

Details of the pagination configuration for this request.

AttributeTypeDescription
pathStringThe base URI path of the API endpoint being requested.
per_pageIntegerSet to the value of the limit parameter on the request.
next_cursorString or nullCursor value for the next request in the paginated set.
prev_cursorString or nullCursor value for the previous request in the paginated set.

Example:

{
  "path": "https://app.contento.io/api/v1/content",
  "per_page": 20,
  "next_cursor": "eyJwdWJsaXNoZWRfYXQiOiIyMDIyLTA2LTA3IDExOjU0OjI5IiwiX3BvaW50c1RvTmV4dEl0ZW1zIjp0cnVlfQ",
  "prev_cursor": "eyJwdWJsaXNoZWRfYXQiOiIyMDIyLTA2LTA3IDExOjU0OjI5IiwiX3BvaW50c1RvTmV4dEl0ZW1zIjpmYWxzZX0"
}

Simple pagination

Simple pagination works by requesting the specific page you want to view via the page query parameter.

You can switch simple pagination on by setting the X-CONTENTO-SIMPLE-PAGINATION header to true for all requests that require it:

Request

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

Parameters

As with cursor pagination the usual parameters are available with the request, the ones that affect simple pagination directly are listed here:

ParameterFormatDefaultAccepted values
limitInteger20The number of results you want in the response.
pageIntegerThe page number you want to fetch e.g. 2.
sortString or Arraypublished_at:descYou must supply values in the following format: attribute:directionread more.

Response

The top level structure of the response is the same as the cursor pagination response, however the internal structure of the links and meta keys will be different.

The whole response for a request with page=2 will look a little something like this:

{
  "data": [ 
    ...
  ],
  "links": {
    "first": "https://app.contento.io/api/v1/content?page=1",
    "last": "https://app.contento.io/api/v1/content?page=33",
    "prev": "https://app.contento.io/api/v1/content?page=1",
    "next": "https://app.contento.io/api/v1/content?page=3"
  },
  "meta": {
    "current_page": 2,
    "from": 21,
    "last_page": 33,
    "links": [
      {
        "url": "https://app.contento.io/api/v1/content?page=1",
        "label": "« Previous",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=1",
        "label": "1",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=2",
        "label": "2",
        "active": true
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=3",
        "label": "3",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=4",
        "label": "4",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=5",
        "label": "5",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=6",
        "label": "6",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=7",
        "label": "7",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=8",
        "label": "8",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=9",
        "label": "9",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=10",
        "label": "10",
        "active": false
      },
      {
        "url": null,
        "label": "...",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=32",
        "label": "32",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=33",
        "label": "33",
        "active": false
      },
      {
        "url": "https://app.contento.io/api/v1/content?page=3",
        "label": "Next »",
        "active": false
      }
    ],
    "path": "https://app.contento.io/api/v1/content",
    "per_page": 20,
    "to": 40,
    "total": 657
  }
}

Provides an interface for quickly getting the first, last previous or next request in the paginated set. URLs will have their page parameter set to the correct value and any other parameters that are present in the request will remain in place.

AttributeTypeDescription
firstString or nullURL for the first request in the paginated set.
lastString or nullURL for the last request in the paginated set.
prevString or nullURL for the previous request in the paginated set.
nextString or nullURL for the next request in the paginated set.

Example:

{
  "first": "https://app.contento.io/api/v1/content?page=1",
  "last": "https://app.contento.io/api/v1/content?page=33",
  "prev": "https://app.contento.io/api/v1/content?page=1",
  "next": "https://app.contento.io/api/v1/content?page=3"
}

meta

Details of the pagination configuration for this request.

AttributeTypeDescription
current_pageIntegerThe number for the current page in the response.
fromIntegerThe position in the total dataset of the first object in this response.
last_pageIntegerThe number for the last page available in the dataset.
linksArrayAn array of link objects.
pathStringThe base API path the request is for, without any parameters.
per_pageIntegerThe number of objects in each page, this matches whatever limit is set to which by default is 20.
toIntegerThe position in the total dataset of the last object in this response.
totalIntegerThe total number of objects in the requested dataset.

Example:

{
  "current_page": 2,
  "from": 21,
  "last_page": 33,
  "links": [
    ...
  ],
  "path": "https://app.contento.io/api/v1/content",
  "per_page": 20,
  "to": 40,
  "total": 657
}

Link objects are only ever returned as part of the meta.links attribute on a simple pagination request. They can be useful for building pagination UI with previous, next and numbered page links.

They have the following attributes:

AttributeTypeDescription
urlString or nullURL for the link.
labelStringA human readable label for the link e.g. 2 or Next ».
activeBooleanWhether this link is the active link for the request.

Example:

{
  "url": "https://app.contento.io/api/v1/content?page=2",
  "label": "2",
  "active": true
}
Previous
Authentication