Document API

The Prismic Document API is an extremely fast, flexible, and powerful engine for your content. This page provides definitions for all of the API parameters.

Overview

Note: This page is a technical reference for the Document API. If you’re starting a project with Prismic, we recommend you use a user-friendly guide for the technology of your choice:

You can also read a beginner-friendly introduction to the Prismic API:

The Prismic Document API is an extremely fast, flexible, and powerful engine for your content.

Your repository has a Repository API Endpoint. This endpoint has information about your repository, including your repository’s refs, which are necessary to make a query to the Document API.

Your Repository API Endpoint is available here:

https://your-repo-name.cdn.prismic.io/api/v2

The Document API is available here:

https://your-repo-name.cdn.prismic.io/api/v2/documents/search

To access the Document API endpoint, you will need a ref. The ref specifies what version of your content to query. A basic query, including a ref, might look like this:

https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=X71BaxIAACMA0NsN

Query URLs, like the one above, will expire as the ref goes out of date. The ref must be up-to-date.

Encoding

All of the Document API options are encoded as URL search parameters. A URL search parameter is a key-value pair. The value must be encoded as a URL component. You can encode the value using JavaScript’s encodeURIComponent() function. Prior to encoding, the key-value pair might look like this:

fetchLinks=[author.name,author.avatar]

After encoding the value, it will look like this:

fetchLinks=%5Bauthor.name%2Cauthor.avatar%5D

One or more of these parameters can be joined with ampersands to form a query string:

page=2&pageSize=5

Append your query string to the API endpoint with a question mark:

https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=X71BaxIAACMA0NsN&page=2&pageSize=5

JavaScript has a built-in URL() constructor to manage search parameters:

const url = new URL(
  "https://your-repo-name.cdn.prismic.io/api/v2/search/documents",
);
url.searchParams.append("ref", "X71BaxIAACMA0NsN");
url.searchParams.append("page", 2);
url.searchParams.append("pageSize", 5);

return url.href;
// https://your-repo-name.cdn.prismic.io/api/v2/search/documents?ref=X71BaxIAACMA0NsN&page=2&pageSize=5

However, there is no need to create and manipulate URLs manually. @prismicio/client will handle the technical parts of performing API requests (including fetching your ref):

import * as prismic from "@prismicio/client"

const client = prismic.createClient("your-repo-name")

const posts = await client.getAllByType("post", { page: 2, pageSize, 5 })

You can use the below parameters to construct your query string.

Limits

The maximum URL length for requests to the Document API is 2048 characters.

The rate limit for the Document API is 200 requests per second. Queries that use the CDN are automatically cached. Cached queries have no rate limit. Since Prismic’s development kits use the CDN by default, most users will never hit this limit. However, there are a few ways you might hit the limit:

  • If you create your own API client that doesn’t use the CDN
  • If you manually invalidate the cache on requests in very rapid succession
  • If you make hundreds of different API requests immediately after publishing a document

The development kit @prismicio/client (version 5 and up) automatically uses the CDN and also automatically handles errors if the rate limit is hit. In that case, the kit will automatically retry the query after one second.

ref (required)

A ref identifies a specific version of your content (for instance: draft, published, or scheduled). Refs are available at the Repository API:

https://your-repo-name.cdn.prismic.io/api/v2

To query your content, you will need to perform one query to get your current ref (which is a short token) and then a second query — using that ref — to get your content. This ensures that the content returned is the correct version and up-to-date.

ref=YHhVOBAAACcACRyo

access_token

A long, secret string required to query content in private repositories. Available in your Prismic repository settings. Required for private repositories.

access_token=MTYwNjMyMjI1NzU5MS5YNzU2UVJJQUFDQUExaV8z.HO-_ve-_ve-_vTpKbSfvv73vv73vv73vv70e77-9CW04B--_ve-_vWJ_b00U77-9Je-_vRoh77-977-9

q

The query parameter (q) accepts a set of filters (encoded as a URI component) as its value. Each filter is enclosed in square brackets, and the set is enclosed in square brackets.

The API will return documents that match every filter if the set includes multiple filters or the query string contains various query parameters.

Most filters accept a path to denote the field being examined and then one or more values to compare in the search. The paths can take two formats, based on the filter: document.[meta-value] or my.[custom-type].[field]. See the following reference:

my.[custom-type].[field]

This path allows you to query a specific field in a custom type. [custom-type] should be the API ID of a custom type, such as “blog_post”. [field] should be the API ID of a field in that custom type, such as “author”.

my.[custom-type].[group-field].[field]

This path allows you to query a field within a group.

document.type

The API ID of a document’s custom type.

document.id

The automatically-assigned document ID, which looks like this: WGvVEDIAAAcuB3lJ

document.tags

The tags assigned to a document. Tags must always be listed in an array.

document.first_publication_date

The date and time that the document was first published. This value never changes.

document.last_publication_date

The date and time that the document was last published. This value is updated every time new edits are published.

document

This path is only used with the fulltext filter. It allows you to search all rich text, title, key text, select, and UID fields in a document.

Each path can be used with specific document fields. This pivot table shows what field types can be used with what paths:

FieldsatnotanyinfulltexthasmissingsimilarnearltgtinRangeDates
Full document textdocument
Tagsdocument.tags
IDdocument.id
Custom Typedocument.type
First publication datedocument.first_publication_date
Last publication datedocument.last_publication_date
UIDmy.[custom-type].uid
Key Textmy.[custom-type].[key-text-field]
Selectmy.[custom-type].[select-field]
Numbermy.[custom-type].[number-field]
Datemy.[custom-type].[date-field]
Content Relationshipmy.[custom-type].[relationship-field]
Booleanmy.[custom-type].[boolean-field]
Rich Textmy.[custom-type].[rich-text-field]
Titlemy.[custom-type].[title-field]
Geopointmy.[custom-type].[geopoint-field]
Timestampmy.[custom-type].[timestamp-field]
Colormy.[custom-type].[color-field]
Linkmy.[custom-type].[link-field]
Imagemy.[custom-type].[image-field]
Embedmy.[custom-type].[embed-field]
Groupmy.[custom-type].[group-field]
Integrationmy.[custom-type].[integration-field]

An essential query parameter to search for a document of the type “article” will look like this:

[[at(document.type,"article")]]

A query parameter to search for a document of type “article,” last published in 2020, will look like this:

[[at(document.type,"article")][date.year(document.last_publication_date,2020)]]

To test queries you can use the Prismic API Browser accessible at https://your-repo-name.prismic.io/api/v2. (Learn more about the API Browser.)

You won’t need to construct query URLs because we have development kits for the most popular web development frameworks. These kits offer helper functions for querying the API. You can learn more about querying with various technologies in our technology guides.

Here’s an example of what a filter query would look like in the API Browser, with our JavaScript kit, and as a URL:

[date.year(document.last_publication_date,2020)]
[at(document.type,"blog-post")]

Here is the full list of filters:

at

Checks that the path matches the described value exactly. It takes a single value for a field at the top level of the document (not in slices) or an array (only for tags).

To query by a content relationship, supply the document ID as the value.

[at(path, value)]

Available values:

path

document.type document.tags document.id my.[custom-type].[uid-field] my.[custom-type].[key-text-field] my.[custom-type].[select-field] my.[custom-type].[number-field] my.[custom-type].[date-field] my.[custom-type].[boolean-field] my.[custom-type].[content-relationship-field]

value

single value (for all but document.tags) array of values (only for document.tags)

Examples:

// All documents of type "product"
[at(document.type, "product")]

// All documents with the tags "Macaron" and "Cupcake"
[at(document.tags, ["Macaron", "Cupcake"])]

// All documents of type "product" with a "price" of 50
[at(my.product.price, 50)]

not

Checks that the path doesn’t match the provided value exactly. It takes a single value or an array. (Arrays are only accepted for tags.)

[not( path, value )]

Accepted values:

path

document.type document.tags document.id my.[custom-type].[uid-field] my.[custom-type].[key-text-field] my.[custom-type].[select-field] my.[custom-type].[number-field] my.[custom-type].[date-field] my.[custom-type].[boolean-field] my.[custom-type].[content-relationship-field]

value

single value (for all but document.tags) array of values (only for document.tags)

Example:

// All documents not of type "product"
[not(document.type, "product")]

// All documents without the tags "Macaron" and "Cupcake"
[not(document.tags, ["Macaron", "Cupcake"])]

// All documents of type "product" without a "price" of 50
[not(my.product.price, 50)]

any

Accepts an array of values and checks whether the fragment matches any of the values in the array. When used with the ID or UID field, it will not necessarily return the documents in the order given in the array.

[any( path, values )]

Accepted values:

path

document.type document.tags document.id my.[custom-type].[uid-field] my.[custom-type].[key-text-field] my.[custom-type].[select-field] my.[custom-type].[number-field] my.[custom-type].[date-field] my.[custom-type].[content-relationship-field]

valuearray of values

Example:

[any(document.type, ["product", "blog-post"])]

in

Checks whether a document’s ID or UID is in an array of IDs or UIDs. It works the same as the any filter but is much faster because it is only used for IDs and UIDs.

Also, unlike the any filter, it returns the documents in the same order as the given array.

[in( path, array )]

Accepted values:

path

document.id my.[custom-type].uid

valuearray of IDs or UIDs

Example with IDs:

[in(document.id,["Wl4CCCcAAAfU5RMd","WiU34h0AAI90y1m2"])]

Example with UIDs:

[in(my.page.uid,["hello-world","about-me"])]

fulltext

Checks if a string is found inside a whole document or within a specific field on a document.

fulltext will search for a single term, passed as a string, or for multiple terms, passed as a string of terms with spaces between them. With multiple terms, the API will return documents that contain all terms.

The search is not case-sensitive and it matches based on the root word, so a search for “Dogs” will include “dog.”

The search considers rich text, title, key text, select, and UID fields. It ignores image alt text in rich text fields. It doesn’t matter if the field is inside a group, a slice, or a slice repeatable section.

The search is ordered by relevance, with more priority given to rich text content, especially headings.

[fulltext( path, value )]

Accepted values:

path

document my.[custom-type].[rich-text-field] my.[custom-type].[title-field] my.[custom-type].[key-text-field] my.[custom-type].[uid] my.[custom-type].[select-field]

valuestring

Example:

// all documents that contain the word "quickstart"
[fulltext(document,"quickstart")]

// all page documents with a description that contains the words "configuration" and "codes"
[fulltext(my.page.description,"configuration codes")]

has

The has filter checks whether a fragment has a value. It will return all the documents of the specified type that contain a value for the specified field.

Works for all content types except groups and slices.

[has( path )]

Accepted values:

pathmy.[custom-type].[field]

Example:

// all "page" documents that have a description
[has(my.page.description)]

missing

The missing filter checks if a fragment doesn’t have a value. It will return all the documents of the specified type that do not contain a value for the specified field.

Works for all content types except groups and slices.

Note that this filter will restrict the results to the custom type implied in the path.

[missing( path )]

Accepted values:

pathmy.[custom-type].[field]

Example:

[missing(my.page.description)]

similar

The similar filter takes the ID of a document, and returns a list of documents with similar content. This allows you to build an automated content discovery feature (for example, a “Related posts” section).

[similar( id, value )]

Accepted values:

idA document ID
value

The maximum number of documents that a term may appear in to still be considered relevant

Example:

[similar("WiU34h0AAI90y1m2", 10)]

geopointNear

The geopointNear filter checks that the value in the path is within the radius of the given coordinates. Distance is measured in kilometers.

The near filter will order the results from nearest to farthest from the given coordinates.

[geopoint.near( path, latitude, longitude, radius )]

Accepted values:

path

my.[custom-type].[geopoint-field]

latitude

Latitude of the center of the search area

longitude

Longitude of the center of the search area

radiusRadius of search in kilometers

Example:

[geopoint.near(my.restaurant.location, 9.656896299, -9.77508544, 10)]

numberLessThan

The numberLessThan filter checks that the value in the number field is less than the value passed into the filter.

This is a strict less-than operator, it will not give values equal to the specified value.

[lt( path, value )]

Accepted values:

pathmy.[custom-type].[number-field]
valueNumber

Example:

[lt(my.product.price, 9.99)]

numberGreaterThan

The numberGreaterThan filter checks that the value in the number field is greater than the value passed into the filter.

This is a strict greater-than operator, it will not give values equal to the specified value.

[gt( path, value )]

Accepted values:

pathmy.[custom-type].[number-field]
valueNumber

Example:

[gt(my.product.price, 9.99)]

numberInRange

The numberInRange filter checks that the value in the path is within the two values passed into the filter.

This is an inclusive search, it will include values equal to the upper and lower limits.

[number.inRange( path, lowerLimit, upperLimit )]

Accepted values:

pathmy.[custom-type].[number-field]
lowerLimitNumber
upperLimitNumber

Example:

[number.inRange(my.product.price, 10, 100)]

Date filters

Prismic has sixteen filters for dates and times. The “after” and “before” filters will not include a date or time equal to the given value. The “between” filters will include dates and times equal to the given values.

// Checks that the path's date is after a given date
[date.after( path, date )]

// Checks that a the path's date in the path is before a given date
[date.before( path, date )]

// Checks that the path's date is between two values
[date.between( path, startDate, endDate )]

// Checks that the path's day of the month is equal to the given day of the month
[date.day-of-month( path, day )]

// Checks that the path's day of the month is after the given day of the month
[date.day-of-month-after( path, day )]

// Checks that the path's day of the month is before the given day of the month
[date.day-of-month-before( path, day )]

// Checks that the path's weekday is equal to the given weekday
[date.day-of-week( path, weekday )]

// Checks that the path's weekday is after the given weekday
[date.day-of-week-after( path, weekday )]

// Checks that the path's weekday is before the given weekday
[date.day-of-week-before( path, weekday )]

// Checks that the path's month is equal to the given month
[date.month( path, month )]

// Checks that the path's month is after the given month
[date.month-after( path, month )]

// Checks that the path's month is before the given month
[date.month-before( path, month )]

// Checks that the path's year is equal to the given year
[date.year( path, year )]

// Checks that the path's hour is equal to the given hour
[date.hour( path, hour )]

// Checks that the path's hour is after the given hour
[date.hour-after( path, hour )]

// Checks that the path's hour is before the given hour
[date.hour-before( path, hour )]

Accepted values:

path

document.first_publication_date document.last_publication_date my.[custom-type].[date-field] my.[custom-type].[timestamp-field]

date startDate endDate

ISO 8601 Standard date: “2002-08-28” ISO 8601 Standard timestamp: “2002-08-28T15:30:00+0300” 13-digit Epoch: 1030545000000

dayDay of month
weekday

Day of week, starting with Monday. Will also accept first-letter capitalized (“Monday”) and all-caps (“MONDAY”). 'monday', 'mon', or 1 'tuesday', 'tue', or 2 'wednesday', 'wed', or 3 'thursday', 'thu', or 4 'friday', 'fri', or 5 'saturday', 'sat', or 6 'sunday', 'sun', or 7

month

Month, starting “january” or 1. Will also accept first-letter capitalized (“January”) and all-caps (“JANUARY”). 'january', 'jan', or 1 'february', 'feb', or 2 'march', 'mar', or 3 'april', 'apr', or 4 'may' or 5 'june', 'jun', or 6 'july', 'jul', or 7 'august', 'aug', or 8 'september', 'sep', or 9 'october', 'oct', or 10 'november', 'nov', or 11 'december', 'dec', or 12

yearYear
hour

An hour as a number, between 0 and 23. Date field values have an hour value of 0.

Example:

This example combines the month and year filters. This query will return content published in May 2020:

[date.year(my.article.example_date, 2020)]
[date.month(my.article.example_date, 'May')]

orderings

This option specifies what field to order your results by, and whether to order them ascending or descending.

Use an orderings object to sort your query results in a given order. The following example will sort blog posts by the date they were originally published, in descending order:

Specify the field with the path my.[custom-type].[field]:

orderings=[my.product.price]

By default, the results will be ordered from lowest to highest. To order results highest to lowest, add desc:

orderings=[my.product.price desc]

To order by multiple fields, use a comma-separated list in the API and an object in JavaScript. The results will be ordered by the first path. When the value of the first path is the same for multiple results, they will be ordered by the second path, and so on.

In this example, products will be sorted by price. Products with the same price will then be sorted by title.

orderings=[my.product.price,my.product.title]

Documents also have a first_publication_date and last_publication_date. These can also be used with orderings:

orderings=[document.first_publication_date]

after

This option works with orderings to return documents after the one specified.

For example, imagine if you have a query that returns the following document IDs (in this order):

V9Zt3icAAAl8Uzob
PqZtvCcAALuRUzmO
VkRmhykAAFA6PoBj
V4Fs8rDbAAH9Pfow
G8ZtxQhAALuSix6R
Ww9yuAvdAhl87wh6

If you add the after option with the a value of "VkRmhykAAFA6PoBj", like this,

after=VkRmhykAAFA6PoBj

your query will return:

V4Fs8rDbAAH9Pfow
G8ZtxQhAALuSix6R
Ww9yuAvdAhl87wh6

By reversing the orderings in your query, you can use this same method to retrieve all the documents before the specified document.

graphQuery

GraphQuery is a query option that enables you to make advanced queries. It allows for selective fetching (only retrieving specific fields) and deep fetching (retrieving content from linked documents and content relationships).

The Document API accepts an encoded GraphQuery string. You can encode the string with JavaScript’s built-in encodeURIComponent() function or with a web service. Prismic’s development kits will automatically encode the string for you.

Request URLs to the Document API are limited to 2048 characters. You can reduce your string length by using line breaks with no spaces or tabs, or you can use a white space removal tool.

Here’s an example:

graphQuery={ post { title } }

Read the complete reference for GraphQuery:

fetch

Please note: fetch is deprecated in favor of graphQuery.

This option is used to make queries faster by only retrieving the specified field(s).

To retrieve a single field, specify it with [custom-type].[field]:

fetch=product.title

To retrieve multiple fields, use array syntax:

fetch=[product.title,product.description]

This option allows you to retrieve a specific content field from a linked document and add it to the document response object.

fetchLinks can not retrieve the following fields:

  • Rich text (anything other than the first element)
  • Any field in a slice (only the slice zone)

To retrieve the linked content, use the format [linked-document-type].[field-on-linked-doc]:

fetchLinks=author.name

To retrieve multiple fields, use array syntax:

fetchLinks=[author.name,author.avatar]

To retrieve a content field inside a group field, use the format [linked-document-type].[group-on-linked-doc].[field-on-linked-doc]:

fetchLinks=author.author_group.name

To retrieve the slice zone, use the format [linked-document-type].body:

fetchLinks=author.body

lang

This option allows you to specify what locale you would like to retrieve content from. By default, the API will return content from your master locale.

To specify a particular locale, pass the locale code:

lang=en-us

To retrieve all locales, pass the wildcard value *:

lang=*

pageSize

This option defines the maximum number of documents that the API will return for your query. It accepts a number. The default is 20, and the maximum is 100.

pageSize=100

page

The page option defines the pagination for the result of your query. It defaults to 1, corresponding to the first page.

page=2

integrationFieldsRef

The integration field allows you to integrate data from third-party services. integrationFieldsRef specifies the version of Integration Field data embedded in Prismic documents to query. You can retrieve the latest integrationFieldsRef for your repository by making a call to the Repository Endpoint, just like you do to retrieve a standard ref. If you omit integrationFieldsRef, you might not get the freshest data from the integration.

 integrationFieldsRef=example-repo~7207b47e-3472-4350-bb0c-5a771c0ea671

routes

The routes option — also called the route resolver — resolves URL paths for every document based on rules defined by the client. If no routes option is specified, the url property will be null.

The route resolver has the properties type, uid, lang, and resolvers. The resolvers property has access to the variables :uid, :lang, and :[resolver]. :lang and :[resolver] can be marked as optional with a question mark ?.

For a full definition, see the route resolver article:

Here is a simple route resolver:

routes=[{"type":"page","path":"/:uid"}]

brokenRoute

The brokenRoute option defines a URL path for broken links.

Broken links occur when a document with inbound content relationships or links is deleted. In the linking documents, the link or content relationship field shows up with type: broken and isBroken: true. The routes option will not generate a url property for broken links.

The path defined with brokenRoute will populate in the url property of broken link and content relationship fields.

brokenRoute=/404