Query by type with the REST API

Here you will find examples of how to query all the documents of a certain type.

The predicate

Here is the predicate you need when querying all of the documents of a certain custom type.

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

You just need to enter the API-ID of the custom type. The following is the predicate to query all the documents of the type blog-post.

Copy
[at(document.type, "blog-post")]

Query by One Type

Example 1

The first example shows how to query all of the documents of the custom type blog-post sorted by their date (from most recent to the oldest).

Here are all the required parameters for this query:

all of type "blog-post"

q=[[at(document.type,"blog-post")]]

sort by date

orderings=[my.blog-post.date]

Example 2

This example shows how to query all of the documents of the custom type video-game sorted alphabetically, limited to 10 games per page, and showing the second page of results.

Here are all the required parameters for this query:

all of type "video-game"

q=[[at(document.type,"video-game")]]

sorted by title

orderings=[my.video-game.title]

10 games per page

pageSize=10

showing the 2nd page

page=2

Query by Multiple Types

This example shows how to query all of the documents of two different custom types: article and blog_post.

Here are all the required parameters for this query:

all of type "article" and "blog_post"

q=[[any(document.type,["article","blog_post"])]]