Delivery GraphQL API reference
Is this page helpful?
https://graphql.kontent.ai/<YOUR_ENVIRONMENT_ID>
.
Use the API to deliver specific content to your website or app. The API responses are cached in a CDN. This makes the content quickly available from wherever you are.
query
. With query parameters, you’re limited by the maximum URL length of 2000 characters.
Authorization: Bearer <YOUR_API_KEY>
. Requests with an incorrect or missing Authorization
header will fail with an error.
https://preview-graphql.kontent.ai/<YOUR_ENVIRONMENT_ID>
Authorization: Bearer <YOUR_PREVIEW_API_KEY>
.QUERY_TOO_COMPLEX
error.
You can find whether your requests are close to the complexity limit by looking at the X-Complexity
header.
Example 1
The following query can return up to 1,000 Articles. Its complexity is 1,000.
Example 2
The following query can return:
X-Request-Charge
header.
When you reach the resource limit for a given time period, the API rejects the request and responds with a 429 HTTP error. This error comes with the Retry-After
header that tells you how many seconds you need to wait before retrying your request. Each failed request is perfectly safe to retry. If you begin to receive 429 errors, reduce the frequency of your requests.
2xx
range indicate a successful request, status codes in the 4xx
range indicate errors caused by an incorrect input (for example, providing an incorrect API key), and status codes in the 5xx
range indicate an error on our side.
If your query contains a mistake, the API might return a 200
with an error message in the response body.
Status code | Description |
200 OK | The request was successful. However, the API might return an error message. For example, if your query is too complex or fails to execute correctly. |
400 Bad Request | The request wasn't successful. Check your request for a missing required parameter or an invalid query parameter value. |
403 Forbidden | The API request was forbidden. Check if your subscription plan comes with GraphQL enabled. |
404 Not Found | The specified environment doesn't exist. |
405 Method Not Allowed | The requested HTTP method is not supported for the specified resource. |
429 Too Many Requests | The rate limit for the API has been exceeded. Try your request again after a few seconds as specified in the Retry-After header. |
5xx Internal Error or Service Unavailable | Something went wrong on our side. Try your request again after a few seconds and use a retry policy. |
article
query for retrieving a single content item.article_All
collection query for retrieving multiple content items.<typeName>_All
(as in article_All
) query. By default, the items are ordered alphabetically by codename.
order
argument in your query. The order
argument requires that you provide a field name and specify whether the order is ascending or descending.
languageFilter
argument in your queries.
If the requested content items don't have content in the specified language, the API follows language fallbacks as specified in your localization settings. To check the language of the returned content items, specify the language
field of the content item's system_
object.
where
argument. The where
argument can be applied only to root collection queries, which are based on your content types such as article_All
, navigationItem_All
, and so on.
In the where
argument, you can specify a single condition with one filter or combine multiple filters using the AND and OR operators.
_system_
fields:
id
(string)codename
(string)name
(string)lastModified
(string)collection
(string)workflow
(string)workflowStep
(string)language
(LanguageFilter!)value
field only)Filter | Description | Example condition | Use with types |
eq | Checks whether the field value matches exactly to the specified filter value. | where: {title: {eq: "My article"}}
where: {_system_: {id: {eq: "<item-id>"}}}
| DateTime, Number, String |
notEq | Checks if the field value is different than the specified value. | where: {_system_: {workflowStep: {notEq: "archived"}}} | DateTime, Number, String |
lt | Checks if the field's value is less than the specified value. | where: {postDate_with_timezone: {value: {lt: "2021-01-01T00:00:00Z"}}} | DateTime, Number |
lte | Checks if the field's datetime value is less than or equal to the specified value. | where: {_system_: {lastModified: {lte: "2021-01-01T00:00:00Z"}}} | DateTime, Number |
gt | Checks if the field's datetime value is greater than the specified value. | where: {postDate_with_timezone: {value: {gt: "2021-01-01T00:00:00Z"}}} | DateTime, Number |
gte | Checks if the field's datetime value is greater than or equal to the specified value. | where: {price: {gte: 10.5}} | DateTime, Number |
in | Checks if the field value matches at least one of the specified array values. | where: {_system_: {collection: {in: ["hr", "marketing"]}}} | DateTime, Number, String |
notIn | Checks if the field value is different than the specified array values. | where: {_system_: {collection: {notIn: ["default"]}}} | DateTime, Number, String |
isEmpty | Checks if the field value is null or empty. | where: {relatedArticles: { isEmpty: true }} | DateTime, Number, String, Array |
containsAll | Checks if the array field value matches all of the specified array values. | where: {topic: { containsAll: ["gadget", "security"] }} | Array |
containsAny | Checks if the field value matches at least one of the specified array values. | where: {topic: { containsAny: ["nature"] }} | Array |
where
arguments, you can use the AND
and OR
operators. Both operators take an array of at least two values and can be nested in one another.
limit
and offset
arguments combined with the predefined totalCount
field.
limit
(Int
) – Specifies the number of objects to retrieve. If not specified, the API returns up to 10 objects. The maximum limit
value is 1,000.offset
(Int
) – Specifies the number of objects to skip. If not specified, the offset
is 0, and the API returns the first page of results._
), converted to PascalCase, and used as a GraphQL name. For content type snippets, the converted codename is prefixed with an underscore. For date & time elements, the converted codename is suffixed with string _with_timezone
.
The GraphQL type names and field names must be unique. If two codenames lead to an identical GraphQL name, the GraphQL schema fails to build correctly. For example, the codenames button
and button_
would lead to the same GraphQL name. In such case, adjust your codenames to avoid collisions.
Examples of codename conversion to GraphQL names:
Original codename | GraphQL object type name | GraphQL query name |
Content type article | Article for single item
Article_All for multiple items
| article for single item
article_All for multiple items
|
Content type fact_about_us | FactAboutUs for single item
FactAboutUs_All for multiple items
| factAboutUs for single item
factAboutUs_All for multiple items
|
Content type snippet metadata | _metadata for the GraphQL field | None. Elements under the content type snippet are available as subfields of the _metadata field. |
Date & time element postDate | postDate_with_timezone for the GraphQL field | None. Data of the date & time element are available as subfields of the postDate_with_timezone field. |
items
field and at least one of its subfields. You can also specify the predefined totalCount
field to find how many items the collection contains.
_system_
field with the content item's metadata._system_
field. The _system_
field is defined by the _Sys
type, which contains your content items' metadata. For example, the content item's last modification date, codename, and so on.
The _Sys
type is used in the GraphQL types generated from your content types.
_system_
field in the predefined system GraphQL types such as _Language
, _ContentType
, _Collection
, _Workflow
, and _WorkflowStep
. In these types, the _system_
field contains partial metadata such as the object's name
or codename
.
url
, name
, description
, type
, size
, width
, and height
.
_Asset
type. The _Asset
type contains the renditions
field referencing customized images.
To display customized images on the website or an app, you first need to apply custom query parameters to the asset's original URL.
_RichTextAsset
type. The _RichTextAsset
type has with an additional field named imageId
. The imageId
field helps you identify the assets that are referenced in the rich text's html
field.
_
). To query the elements of the snippet, you need to specify the subfields of the snippet field.
For example, a snippet named Metadata will have the following GraphQL type.
value
field.
value
and display_timezone
fields.
value
field contains an ISO-8610 formatted string such as 2021-11-18T08:43:19Z
. Time in this field is displayed and interpreted as UTC.display_timezone
field contains an IANA time zone name such as Europe/Berlin
. This information is used to display the time offset of the date & time element in the UI. The time zone doesn't modify the date specified in the value
field. Check the full list of supported time zones.Float
fields.
html
, itemHyperlinks
, linkedItems
, components
, and assets
fields.
For an overview of the HTML5 tags you might get in the html
string field, check HTML5 elements allowed in rich text.
The data type of the linkedItems
, components
and itemHyperlinks
fields can change depending on the limitations set for the rich text element. With no limitations set for the type of linked items, components, and item links, the GraphQL type for rich text is the following.
If the components, linked items, or item links you can insert into rich text are limited to a specific content type, the GraphQL API reflects the limitation by generating several custom types.
For example, if the Body copy rich text element in an Article content type has the components and linked items limited to a content type named Tweet, you'll see the following GraphQL types.
String
fields. These fields contain plaintext.
String
fields. These fields contain plaintext.curl --request POST \
--url 'https://graphql.kontent.ai/<YOUR_ENVIRONMENT_ID>' \
--header 'content-type: application/graphql'
--data-raw '{article(codename:"my_article"){title}}'
curl -g --request GET 'https://graphql.kontent.ai/<YOUR_ENVIRONMENT_ID>?query={article(codename:"on_roasts"){title}}'
curl --request POST \
--url 'https://graphql.kontent.ai/<YOUR_ENVIRONMENT_ID>' \
--header 'content-type: application/graphql'
--header 'Authorization: Bearer <YOUR_DELIVERY_API_KEY>'
--data-raw '{<YOUR_GRAPHQL_QUERY>}'
curl --request POST \
--url 'https://preview-graphql.kontent.ai/<YOUR_ENVIRONMENT_ID>' \
--header 'content-type: application/graphql'
--header 'Authorization: Bearer <YOUR_PREVIEW_API_KEY>'
--data-raw '{<YOUR_GRAPHQL_QUERY>}'
query GetArticles {
article_All(limit: 1000) {
items {
title
}
}
}
query GetArticlesWithRelatedArticles {
article_All(limit: 100) {
items {
title
relatedArticles(limit: 20) {
items {
_system_ {
name
}
}
}
}
}
}
# Total query depth = 5
query GetImagesInArticle {
article_All { # level 0
items { # level 1
bodyCopy { # level 2
assets { # level 3
items { # level 4
url # level 5
}
}
}
}
}
}
# Total query depth = 4
query GetPostsAndArticles {
# Depth is 2 levels
article_All { # level 0
items { # level 1
title # level 2
url # level 2
}
}
# Depth is 2 levels
post_All { # level 0
items { # level 1
title # level 2
url # level 2
}
}
}
query GetArticleByCodename {
article(codename: "my_article") {
title
slug
}
}
query GetArticleById {
article(id: "c706af79-2a4f-41e4-9bec-8c8383e00944") {
title
slug
}
}
query GetArticles {
article_All {
items {
title
slug
}
}
}
query GetOrderedItems {
# Get articles ordered by their title from Z to A
article_All(order: {title: desc}) {
items {
title
}
}
# Blog posts ordered by codename from A to Z
post_All(order: {_system_: {codename: asc}}) {
items {
title
}
}
}
query GetSpanishArticles {
# Requests articles in Spanish
article_All(languageFilter: {languageCodename: "es-ES"}) {
items {
_system_ {
language {
_system_ {
codename
}
}
}
title
slug
}
}
}
query GetNonArchivedArticles {
article_All(where: {_system_: {workflowStep: {notEq: "archived"}}}) {
items {
title
}
}
}
query GetArticlesByComplexCondition {
article_All(where: {AND: [
{OR: [
{title: {eq: "On Roasts"}},
{title: {eq: "Donate with us"}},
]},
{summary: {isEmpty: false}}
]}) {
items {
title
}
}
}
# Paginating articles
query GetPaginatedArticles {
article_All(limit: 10, offset: 10) {
items {
title
}
offset # Returns the specified offset
limit # Returns the specified limit
totalCount # Returns the total number of content items that match the query
}
}
# Paginating linked content in rich text
query GetPaginatedLinkedItems {
article_All {
items {
bodyCopy {
html
linkedItems(offset: 10, limit: 10) {
items {
_system_ {
codename
}
}
offset # Returns the specified offset
limit # Returns the specified limit
totalCount # Returns the total number of content items that match the query
}
}
}
}
}
type Article implements _Item {
...
teaserImage( # Asset element
offset: Int!
limit: Int!
totalCount: Int!
): _AssetCollection!
relatedArticles( # Linked items element
offset: Int!
limit: Int!
totalCount: Int!
): _ItemCollection!
personas( # Taxonomy element
offset: Int!
limit: Int!
totalCount: Int!
): _TaxonomyTermCollection!
}
query HowToQueryCollectionFields {
article_All {
items {
teaserImage {
items {
name
}
totalCount # Returns the total number of assets inserted in the asset element
}
personas {
items {
_system_ {
codename
}
}
totalCount # Returns the total number of selected taxonomy terms
}
relatedArticles {
items {
... on Article {
title
}
}
totalCount # Returns the total number of items linked in the element
}
}
totalCount # Returns the total number of articles matching the query
}
}
type Article implements _Item {
_system_: _Sys! # The content item's metadata.
title: String! # Text element
teaserImage( # Asset element
offset: Int = 0
limit: Int = 10
): _AssetCollection!
postDate_with_timezone: _DateAndTime # Date & time element
bodyCopy: _RichText! # Rich text element
relatedArticles( # Linked items element
offset: Int = 0
limit: Int = 10
): _ItemCollection!
personas( # Taxonomy element
offset: Int = 0
limit: Int = 10
): _TaxonomyTermCollection!
urlPattern: String! # URL slug element
}
type _Sys {
name: String! # The content item's display name.
codename: String! # The content item's codename.
language: _Language! # Metadata of the content item's language.
type: _ContentType! # Metadata of the content item's content type.
lastModified: DateTime! # ISO-8601 formatted date and time of the last change to user-content of the content item. The value is not affected when moving content items through workflow steps.
collection: _Collection! # Metadata of the content item's collection.
workflow: _Workflow! # Metadata of the content item's current workflow.
workflowStep: _WorkflowStep! # Metadata of the content item's current workflow step.
id: Guid! # The content item's internal ID.
}
type _Collection {
_system_: _CollectionSys! # The collection's predefined system fields.
}
type _CollectionSys {
codename: String! # The collection's codename.
}
type _ContentType {
_system_: _ContentTypeSys! # The content type's predefined system fields.
}
type _ContentTypeSys {
name: String! # The content type's display name.
codename: String! # The content type's codename.
}
type _Language {
_system_: _LanguageSys! # The language's predefined system fields.
}
type _LanguageSys {
name: String! # The language's display name.
codename: String! # The language's codename.
}
type _Workflow {
_system_: _WorkflowSys! # The workflow's predefined system fields.
}
type _WorkflowSys {
codename: String! # The workflow's codename.
}
type _WorkflowStep {
_system_: _WorkflowStepSys! # The workflow step's predefined system fields.
}
type _WorkflowStepSys {
codename: String! # The workflow step's codename.
}
type _Asset implements _AssetInterface {
renditions: _AssetRenditionCollection # List of renditions available for this asset.
url: String! # The asset's absolute URL.
name: String # The asset's display name.
description: String # The asset's alt text description for a specific language.
type: String # The file's MIME type.
size: Int # The file's size in bytes.
width: Int # The image's width in pixels.
height: Int # The image's height in pixels.
}
type _AssetRenditionCollection {
offset: Int!
limit: Int!
totalCount: Int!
items: [_Rendition!]! # Individual asset rendition objects.
}
type _Rendition {
preset: String! # The image preset's codename.
preset_id: String! # The image preset's ID.
rendition_id: String! # The rendition's ID.
query: String! # Parameters set for the image rendition. Need to be concatenated with the original asset's URL to customize the image.
width: Int! # The rendition's width.
height: Int! # The rendition's height.
}
type _RichTextAsset implements _AssetInterface {
imageId: String! # Identifier of the asset as used in the rich text element.
url: String! # The asset's absolute URL.
name: String # The asset's display name.
description: String # The asset's alt text description for a specific language.
type: String # The file's MIME type.
size: Int # The file's size in bytes.
width: Int # The image's width in pixels.
height: Int # The image's height in pixels.
}
type Metadata {
metaTitle: String!
metaDescription: String!
}
type Article implements _Item {
_system_: _Sys! # The content item's predefined system fields.
...
_metadata: Metadata! # The Metadata type with subfields for each element in the snippet
}
type _CustomElement {
value: String # The custom element's value as a string.
}
type _DateAndTime {
value: DateTime # The element's datetime output.
display_timezone: String # The element's display timezone.
}
type Article implements _Item {
_system_: _Sys! # The content item's predefined system fields.
...
relatedContent: _ItemCollection! # Linked items element without content type limitation
}
type Article implements _Item {
_system_: _Sys! # The content item's predefined system fields.
...
relatedArticle: Article # Linked items element limited to a single Article content type
relatedArticles: Article_RelatedArticles_Collection! # Linked items element limited Article content types
}
type Article_RelatedArticles_Collection {
offset: Int!
limit: Int!
items: [Article!]!
}
type _MultipleChoiceOptionCollection {
offset: Int!
limit: Int!
items: [_MultipleChoiceOption!]! # Specifies the selected multiple choice options.
}
type _MultipleChoiceOption {
_system_: _MultipleChoiceOptionSys! # The multiple choice option's predefined system fields.
}
type _MultipleChoiceOptionSys {
name: String! # The multiple choice option's display name.
codename: String! # The multiple choice option's codename.
}
type Article implements _Item {
_system_: _Sys! # The content item's predefined system fields.
...
bodyCopy: _RichText! # Rich text element without type limitations
}
type _RichText {
html: String! # The rich text's HTML output. Contains references to assets, links to content items, linked content, and components.
itemHyperlinks: _ItemCollection! # Contains the content items referenced in hyperlinks.
assets: _RichTextAssetCollection! # Contains the assets inserted into the rich text.
linkedItems: _ItemCollection! # Contains the content items inserted into the rich text.
components: _ItemCollection! # Contains the components inserted into the rich text.
}
type Article implements _Item {
_system_: _Sys! # The content item's predefined system fields.
...
bodyCopy: Article_BodyCopy! # Rich text element with custom type limitations
}
type Article_BodyCopy {
html: String!
itemHyperlinks: _ItemCollection!
assets: _RichTextAssetCollection!
components: Article_BodyCopy_Components_Collection!
linkedItems: Article_BodyCopy_LinkedItems_Collection!
}
type Article_BodyCopy_Components_Collection {
offset: Int!
limit: Int!
items: [Tweet!]!
}
type Article_BodyCopy_LinkedItems_Collection {
offset: Int!
limit: Int!
items: [Tweet!]!
}
type _TaxonomyTermCollection {
offset: Int!
limit: Int!
items: [_TaxonomyTerm!]! # Specifies the selected taxonomy terms.
}
type _TaxonomyTerm {
_system_: _TaxonomyTermSys! # The taxonomy term's predefined system fields.
}
type _TaxonomyTermSys {
name: String! # The taxonomy term's display name.
codename: String! # The taxonomy term's codename.
}
content-type
headerWith the content-type
header set to application/graphql
, you need to provide your GraphQL query directly in the request body. If you set the header to application/json
, wrap your GraphQL query in valid JSON like this {"query":"{<YOUR_GRAPHQL_QUERY>}"}
.Array
, Boolean
, DateTime
, Float
, Guid
, Int
, String
.