Document API

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:

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

The Document API is available here:

Copy
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:

Copy
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:

Copy
fetchLinks=[author.name,author.avatar]

After encoding the value, it will look like this:

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

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

Copy
page=2&pageSize=5

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

Copy
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:

Copy
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):

Copy
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:

Copy
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.

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
ref=YHhVOBAAACcACRyo
Encoded
Copy
ref=YHhVOBAAACcACRyo
JavaScript
Copy
{ ref: 'YHhVOBAAACcACRyo' }

SDKs automatically fetch your ref

Our API development kits, such as @prismicio/client, provide query helper functions that perform the first query for you, so you don't need to worry about it.

access_token

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

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
access_token=MTYwNjMyMjI1NzU5MS5YNzU2UVJJQUFDQUExaV8z.HO-_ve-_ve-_vTpKbSfvv73vv73vv73vv70e77-9CW04B--_ve-_vWJ_b00U77-9Je-_vRoh77-977-9
Encoded
Copy
access_token=MTYwNjMyMjI1NzU5MS5YNzU2UVJJQUFDQUExaV8z.HO-_ve-_ve-_vTpKbSfvv73vv73vv73vv70e77-9CW04B--_ve-_vWJ_b00U77-9Je-_vRoh77-977-9
JavaScript
Copy
{ 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.

What is a filter?

A filter is a search argument. It tells the API what content to search for. Prismic has dozens of built-in filters, which can accept countless variables — making for infinitely flexible querying. For example, the filter "at" seeks an exact match between a field of your document and a value you provide. at(document.type, "post") looks for all documents that have a "type" matching "post." Similarly, there are filters for "not," "any," "date," and much more.

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]
Integration Fieldsmy.[custom-type].[integration-field]

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

  • Unencoded
  • Encoded
Unencoded
Copy
[[at(document.type,"article")]]
Encoded
Copy
%5B%5Bat(document.type%2C%22article%22)%5D%5D

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

  • Unencoded
  • Encoded
Unencoded
Copy
[[at(document.type,"article")][date.year(document.last_publication_date,2020)]]
Encoded
Copy
%5B%5Bat(document.type%2C%22article%22)%5D%5Bdate.year(document.last_publication_date%2C2020)%5D%5D

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:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[date.year(document.last_publication_date,2020)]
[at(document.type,"blog-post")]
JavaScript
Copy
import * as prismic from '@prismicio/client'

const endpoint = prismic.getEndpoint('your-repo-name')
const client = prismic.createClient(endpoint)

const init = async () => {
  client.get({
    filters: [
      prismic.filter.dateYear('document.last_publication_date', 2020),
      prismic.filter.at('document.type', 'blog-post'),
    ],
  })
}

init()
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bdate.year(document.last_publication_date%2C2020)%5D%5Bat(document.type%2C%22blog-post%22)%5D%5D

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.

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[at(path, value)]
JavaScript
Copy
prismic.filter.at( path, value )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=your_ref&at(path%2Cvalue)%5D%5D

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:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
// 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)]
JavaScript
Copy
// All documents of type "product"
prismic.filter.at('document.type', 'product')

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

// All documents of type "product" with a "price" of 50
prismic.filter.at('my.product.price', 50)
URL
Copy
// All documents of type "product"
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bat(document.type%2C%22product%22)%5D%5D

// All documents with the tags "Macaron" and "Cupcake"
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bat(document.tags%2C%5B%22Macaron%22%2C%22Cupcake%22%5D)%5D%5D

// All documents of type "product" with a "price" of 50
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bat(my.product.price%2C50)%5D%5D

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.)

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[not( path, value )]
JavaScript
Copy
prismic.filter.not( path, value )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bnot(path%2Cvalue)%5D%5D

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:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
// 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)]
JavaScript
Copy
// All documents not of type "product"
prismic.filter.not('document.type', 'product')

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

// All documents of type "product" without a "price" of 50
prismic.filter.not('my.product.price', 50)
URL
Copy
// All documents not of type "product"
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bnot(document.type%2C%22product%22)%5D%5D

// All documents without the tags "Macaron" and "Cupcake"
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bnot(document.tags%2C%5B%22Macaron%22%2C%22Cupcake%22%5D)%5D%5D

// All documents of type "product" without a "price" of 50
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bnot(my.product.price%2C50)%5D%5D

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.

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[any( path, values )]
JavaScript
Copy
prismic.filter.any( path, values )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bany(path%2Cvalues)%5D%5D

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]

value

array of values

Example:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[any(document.type, ["product", "blog-post"])]
JavaScript
Copy
prismic.filter.any('document.type', ['product', 'blog-post'])
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bany(document.type%2C%5B%22product%22%2C%22blog-post%22%5D)%5D%5D

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.

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[in( path, array )]
JavaScript
Copy
prismic.filter.in( path, array )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bin(path%2Carray)%5D%5D

Accepted values:

path

document.id

my.[custom-type].uid

value

array of IDs or UIDs

Example with IDs:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[in(document.id,["Wl4CCCcAAAfU5RMd","WiU34h0AAI90y1m2"])]
JavaScript
Copy
prismic.filter.in('document.id', ['Wl4CCCcAAAfU5RMd','WiU34h0AAI90y1m2'])
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bin(document.id%2C%5B%22Wl4CCCcAAAfU5RMd%22%2C%22WiU34h0AAI90y1m2%22%5D)%5D%5D

Example with UIDs:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[in(my.page.uid,["hello-world","about-me"])]
JavaScript
Copy
prismic.filter.in('my.page.uid', ['hello-world','about-me'])
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bin(my.page.uid%2C%5B%22hello-world%22%2C%22about-me%22%5D)%5D%5D

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.

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[fulltext( path, value )]
JavaScript
Copy
prismic.filter.fulltext( path, value )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bfulltext(path%2Cvalue)%5D%5D

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]

value

string

Example:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
// 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")]
JavaScript
Copy
// all documents that contain the word "quickstart"
prismic.filter.fulltext('document','quickstart')

// all page documents with a description that contains the words "configuration" and "codes"
prismic.filter.fulltext('my.page.description','configuration codes')
URL
Copy
// all documents that contain the word "quickstart"
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bfulltext(document%2C%22quickstart%22)%5D%5D

// all page documents with a description that contains the words "configuration" and "codes"
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bfulltext(my.page.description%2C%22configuration%codes%22)%5D%5D

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.

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[has( path )]
JavaScript
Copy
prismic.filter.has( path )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bhas(path)%5D%5D

Accepted values:

path

my.[custom-type].[field]

Example:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
// all "page" documents that have a description
[has(my.page.description)]
JavaScript
Copy
// all "page" documents that have a description
prismic.filter.has('my.page.description')
URL
Copy
// all "page" documents that have a description
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bhas(my.page.description)%5D%5D

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.

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[missing( path )]
JavaScript
Copy
prismic.filter.missing( path )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bmissing(path)%5D%5D

Accepted values:

path

my.[custom-type].[field]

Example:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[missing(my.page.description)]
JavaScript
Copy
prismic.filter.missing('my.page.description')
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bmissing(my.page.description)%5D%5D

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).

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[similar( id, value )]
JavaScript
Copy
prismic.filter.similar( id, value )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bsimilar(id%2C%20value)%5D%5D

Accepted values:

id

A document ID

value

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

Example:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[similar("WiU34h0AAI90y1m2", 10)]
JavaScript
Copy
prismic.filter.similar('WiU34h0AAI90y1m2', 10)
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bsimilar(%22WiU34h0AAI90y1m2%22%2C%2010)%5D%5D

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.

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[geopoint.near( path, latitude, longitude, radius )]
JavaScript
Copy
prismic.filter.geopointNear( path, latitude, longitude, radius )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bgeopoint.near(%20path%2C%20latitude%2C%20longitude%2C%20radius%20)%5D%5D

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

radius

Radius of search in kilometers

Example:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[geopoint.near(my.restaurant.location, 9.656896299, -9.77508544, 10)]
JavaScript
Copy
prismic.filter.geopointNear('my.restaurant.location', 9.656896299, -9.77508544, 10)
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5Bgeopoint.near(my.restaurant.location%2C%209.656896299%2C%20-9.77508544%2C%2010)%5D

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.

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[lt( path, value )]
JavaScript
Copy
prismic.filter.numberLessThan( path, value )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Blt(%20path%2C%20value%20)%5D%5D%0A

Accepted values:

path

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

value

Number

Example:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[lt(my.product.price, 9.99)]
JavaScript
Copy
prismic.filter.numberLessThan('my.product.price', 9.99)
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Blt(%20my.product.price%2C%209.99%20)%5D%5D

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.

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[gt( path, value )]
JavaScript
Copy
prismic.filter.numberGreaterThan( path, value )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bgt(%20path%2C%20value%20)%5D%5D%0A

Accepted values:

path

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

value

Number

Example:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[gt(my.product.price, 9.99)]
JavaScript
Copy
prismic.filter.numberGreaterThan('my.product.price', 9.99)
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bgt(%20my.product.price%2C%209.99%20)%5D%5D

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.

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[number.inRange( path, lowerLimit, upperLimit )]
JavaScript
Copy
prismic.filter.numberInRange( path, lowerLimit, upperLimit )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bnumber.inRange(%20path%2C%20lowerLimit%2C%20upperLimit%20)%5D%5D

Accepted values:

path

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

lowerLimit

Number

upperLimit

Number

Example:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[number.inRange(my.product.price, 10, 100)]
JavaScript
Copy
prismic.filter.numberInRange('my.product.price', 10, 100 )
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5B%5Bnumber.inRange(my.product.price%2C%2010%2C%20100)%5D%5D

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.

  • API Browser
  • JavaScript
API Browser
Copy
// 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 )]
JavaScript
Copy
// Checks that the path's date is after a given date
prismic.filter.dateAfter( path, date )

// Checks that a the path's date in the path is before a given date
prismic.filter.dateBefore( path, date )

// Checks that the path's date is between two values
prismic.filter.dateBetween( path, startDate, endDate )

// Checks that the path's day of the month is equal to the given day of the month
prismic.filter.dateDayOfMonth( path, day )

// Checks that the path's day of the month is after the given day of the month
prismic.filter.dateDayOfMonthAfter( path, day )

// Checks that the path's day of the month is before the given day of the month
prismic.filter.dateDayOfMonthBefore( path, day )

// Checks that the path's weekday is equal to the given weekday
prismic.filter.dateDayOfWeek( path, weekday )

// Checks that the path's weekday is after the given weekday
prismic.filter.dateDayOfWeekAfter( path, weekday )

// Checks that the path's weekday is before the given weekday
prismic.filter.dateDayOfWeekBefore( path, weekday )]

// Checks that the path's month is equal to the given month
prismic.filter.dateMonth( path, month )

// Checks that the path's month is before the given month
prismic.filter.dateMonthBefore( path, month )

// Checks that the path's month is after the given month
prismic.filter.dateMonthAfter( path, month )

// Checks that the path's year is equal to the given year
prismic.filter.dateYear( path, year )

// Checks that the path's hour is equal to the given hour
prismic.filter.dateHour( path, hour )

// Checks that the path's hour is after the given hour
prismic.filter.dateHourAfter( path, hour )

// Checks that the path's hour is before the given hour
prismic.filter.dateHourBefore( 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

day

Day 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
year

Year

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:

  • API Browser
  • JavaScript
  • URL
API Browser
Copy
[date.year(my.article.example_date, 2020)]
[date.month(my.article.example_date, 'May')]
JavaScript
Copy
[
  prismic.filter.dateYear('my.article.example_date', 2020),
  prismic.filter.dateMonth('my.article.example_date', 'May')
]
URL
Copy
https://your-repo-name.cdn.prismic.io/api/v2/documents/search?ref=WmdIBCcAAHhUDe_K&q=%5Bdate.year(my.article.example_date%2C%202020)%5D%0A%5Bdate.month(my.article.example_date%2C%20%22May%22)%5D

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]:

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
orderings=[my.product.price]
Encoded
Copy
orderings=%5Bmy.product.price%5D
JavaScript
Copy
{
  orderings: {
    field: 'my.product.price',
  },
}

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

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
orderings=[my.product.price desc]
Encoded
Copy
orderings=%5Bmy.product.price%20desc%5D
JavaScript
Copy
{
  orderings: {
    field: 'my.product.price',
    direction: '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.

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
orderings=[my.product.price,my.product.title]
Encoded
Copy
orderings=%5Bmy.product.price%2Cmy.product.title%5D
JavaScript
Copy
{
  "orderings": [
    {
      "field": "my.product.price"
    },
    {
      "field": "my.product.title"
    }
  ]
}

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

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
orderings=[document.first_publication_date]
Encoded
Copy
orderings=%5Bdocument.first_publication_date%5D
JavaScript
Copy
{
  orderings: {
    field: '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):

Copy
V9Zt3icAAAl8Uzob
PqZtvCcAALuRUzmO
VkRmhykAAFA6PoBj
V4Fs8rDbAAH9Pfow
G8ZtxQhAALuSix6R
Ww9yuAvdAhl87wh6

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

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
after=VkRmhykAAFA6PoBj
Encoded
Copy
after=VkRmhykAAFA6PoBj
JavaScript
Copy
{ after: 'VkRmhykAAFA6PoBj' }

your query will return:

Copy
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:

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
graphQuery={ post { title } }
Encoded
Copy
graphQuery=%7Bpost%7Btitle%7D%7D
JavaScript
Copy
{ 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]:

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
fetch=product.title
Encoded
Copy
fetch=product.title
JavaScript
Copy
{ fetch: 'product.title' }

To retrieve multiple fields, use array syntax:

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
fetch=[product.title,product.description]
Encoded
Copy
fetch=%5Bproduct.title%2Cproduct.description%5D
JavaScript
Copy
{ fetch: ['product.title', 'product.description'] }

fetchLinks

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]:

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
fetchLinks=author.name
Encoded
Copy
fetchLinks=author.name
JavaScript
Copy
{ fetchLinks: 'author.name' }

To retrieve multiple fields, use array syntax:

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
fetchLinks=[author.name,author.avatar]
Encoded
Copy
fetchLinks=%5Bauthor.name%2Cauthor.avatar%5D
JavaScript
Copy
{ 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]:

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
fetchLinks=author.author_group.name
Encoded
Copy
fetchLinks=author.author_group.name
JavaScript
Copy
{ fetchLinks: ['author.author_group.name'] }

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

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
fetchLinks=author.body
Encoded
Copy
fetchLinks=author.body
JavaScript
Copy
{ 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:

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
lang=en-us
Encoded
Copy
lang=en-us
JavaScript
Copy
{ lang: 'en-us' }

To retrieve all locales, pass the wildcard value *:

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
lang=*
Encoded
Copy
lang=*
JavaScript
Copy
{ 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.

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
pageSize=100
Encoded
Copy
pageSize=100
JavaScript
Copy
{ pageSize: 100 }

page

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

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
page=2
Encoded
Copy
page=2
JavaScript
Copy
{ 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.

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
 integrationFieldsRef=example-repo~7207b47e-3472-4350-bb0c-5a771c0ea671
Encoded
Copy
 integrationFieldsRef=example-repo~7207b47e-3472-4350-bb0c-5a771c0ea671
JavaScript
Copy
{ 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:

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
routes=[{"type":"page","path":"/:uid"}]
Encoded
Copy
routes=%5B%7B%22type%22%3A%22page%22%2C%22path%22%3A%22%2F%3Auid%22%7D%5D
JavaScript
Copy
{ 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.

  • Unencoded
  • Encoded
  • JavaScript
Unencoded
Copy
brokenRoute=/404
Encoded
Copy
brokenRoute=%2F404
JavaScript
Copy
{ brokenRoute: "/404" }

Was this article helpful?
Not really
Yes, Thanks

Can't find what you're looking for? Spot an error in the documentation? Get in touch with us on our Community Forum or using the feedback form above.