Filtering

Filtering allows you to query your content for items which match a set of parameters. You can define these parameters by adding the filter parameter to your request.

Basic Filtering

The available filter options will depend on the fields that were defined within the content type that is being filtered and the types of those fields. Each field type supports a different set of filters.

Supplying just one filter will only return items which match the specified constraint. For example, the below example will only return books which have a title that equals “My Awesome Book”.

GET /book?filter[title][_eq]=My Awesome Book
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?filter[title][_eq]=My Awesome Book \
     -H 'Content-Type: application/vnd.api+json'

If you specify multiple filters, they will be combined using an AND expression. Extending the previous example, the following will only return books that were also published after 1st January 2020.

GET /book?filter[title][_eq]=My Awesome Book&filter[publishedDate][_gt]=2020-01-01
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?filter[title][_eq]=My Awesome Book&filter[publishedDate][_gt]=2020-01-01 \
     -H 'Content-Type: application/vnd.api+json'

AND / OR

You can also go further and provide the special _AND and _OR filters which allow you to create more complicated filter expressions.

The below example uses the _OR filter and will only return books which were published after 1st January 2020 but were also given a 5 star rating or are in the “Techology” genre.

GET /book?filter[publishedDate][_gt]=2020-01-01&filter[_OR][][rating][_eq]=5&filter[_OR][][genre][_eq]=Technology
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?filter[publishedDate][_gt]=2020-01-01&filter[_OR][][rating][_eq]=5&filter[_OR][][genre][_eq]=Technology \
     -H 'Content-Type: application/vnd.api+json'

Available Filters for Field Types

As mentioned earlier, the types of filters that are available depends on the fields and the types of those fields that are defined within the content model for the content type being filtered.

This section will cover the list of available filters for each possible field type.

Boolean

Filter for records that have the specified field populated or not.
GET /book?filter[booleanField][_exists]=true
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?filter[booleanField][_exists]=true \
     -H 'Content-Type: application/vnd.api+json'

Date/Time

Filter for records that have the specified field populated or not.
GET /book?filter[dateTimeField][_exists]=true
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?filter[dateTimeField][_exists]=true \
     -H 'Content-Type: application/vnd.api+json'

Decimal

Filter for records that have the specified field populated or not.
GET /book?filter[decimalField][_exists]=true
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?filter[decimalField][_exists]=true \
     -H 'Content-Type: application/vnd.api+json'

Image

Image fields do not currently support filtering, though it will be coming in a future release.

Integer

Filter for records that have the specified field populated or not.
GET /book?filter[integerField][_exists]=true
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?filter[integerField][_exists]=true \
     -H 'Content-Type: application/vnd.api+json'

Markdown

Filter for records that have the specified field populated or not.
GET /book?filter[markdownField][_exists]=true
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?filter[markdownField][_exists]=true \
     -H 'Content-Type: application/vnd.api+json'

Relationship

Relationship fields do not currently support filtering, though it will be coming in a future release.

Select (Dropdown)

Filter for records that have the specified field populated or not.
GET /book?filter[selectField][_exists]=true
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?filter[selectField][_exists]=true \
     -H 'Content-Type: application/vnd.api+json'

Text (Single Line)

Filter for records that have the specified field populated or not.
GET /book?filter[textSingleField][_exists]=true
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?filter[textSingleField][_exists]=true \
     -H 'Content-Type: application/vnd.api+json'

Text (Multi Line)

Filter for records that have the specified field populated or not.
GET /book?filter[textMultiField][_exists]=true
curl https://{SPACE_ID}.spaces.lexascms.com/delivery/jsonapi/book?filter[textMultiField][_exists]=true \
     -H 'Content-Type: application/vnd.api+json'

© 2020 Status200 Ltd.