Query by ID or UID

This page gives examples of how to query for a document either by its ID or its UID with the Prismic predicates.

Querying by Language

Note that if you are trying to query a document that isn't in the master language of your repository, you will need to specify the language code or wildcard language value. You can read how to do this on the Query by Language page.

Query by ID

Let's see what all you need to query a document by an ID.

The predicate

In order to do this query we will use the at predicate. It will look like this.

Copy
[at(document.id, "{id}")]

Example

This is an example showing how to query the document with the id WAjgAygAAN3B0a-a.

Here is the required parameter for this query:

query by id

q=[[at(document.id,"WAjgAygAAN3B0a-a")]]

Query by UID

Let's see what all you need to query a document by an UID.

The predicate

In order to do this query we will use the at predicate. It will look like this.

Copy
[at(my.{custom-type}.uid, "{uid}")]

{custom-type}

The API-ID of the custom type

{uid}

The UID of the target document

Example

This is an example showing how to query the document of the type page by its uid about-us.

Here is the required parameter for this query:

query by id

q=[[at(my.page.uid,"about-us")]]

Query by language with the UID

It's possible that you may have documents in different languages with the same UID value. In that case, you will need to specify the language code in order to retrieve the correct document.

If you need to query all the language versions that share the same UID, then you can specify the language wildcard in order to retrieve them all at the same time.

To see how to specify either the language code or the wildcard, check out the Query by language page.