Content API
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.
/v1/content/{id}
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"
}
/v1/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.
Parameter | Formats | Default | Accepted values |
---|---|---|---|
author | String or Array | ID of the author(s) you want to filter by. | |
content_type | String or Array | Handle of the content type you want to filter by. | |
content_type_id | String or Array | ID of the content type you want to filter by. | |
cursor | String | Cursor for pagination. | |
limit | Integer | 20 | The number of results you want in the response. |
slug | String or Array | Slug of the specific content object you want to retrieve. | |
sort | String or Array | published_at:desc | You must supply values in the following format: attribute:direction — read 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.
Attribute | Type | Description |
---|---|---|
data | Array | Sorted array of content objects or an empty array if nothing can be found. |
links | Object | A links pagination object. |
meta | Object | A 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
}
}