Filter content to get what you need
The Delivery API provides several filters to help you refine your requests based on your requirements. To choose the right one, think about what you know about the content you want to get. There’s a filter for every use case.Find a scenario relevant to you and adjust the code samples to get the content you need.
Filter by item ID or a codename
To get an item based on its identifier (like ID or codename), use the equals filter. For example, if you need to get an item by its internal ID, you match the item's ID (found insystem.id
) against the ID value you have.
// Gets an item by its internal ID
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterEquals("system.id", "2f7288a1-cfc8-47be-9bf1-b1d312f7da18")
.build()
);
Tip: This approach works equally well for other
system
properties of the content item object. For example, system.workflow_step
, system.collection
, system.last_modified
.If you have multiple identifiers of a single type (for example, only IDs or codenames) and want to retrieve them in a single request, use the
in
filter.// Gets three items by their codenames. The codenames are unique per project.
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterIn("system.codename", "delivery_api", "get_content", "hello_world")
.build()
);
Filter by content types
To get items based on a single content type, specify the content type's codename (
system.type
) using the equals
filter.// Gets items of content type Product
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterEquals("system.type", "product")
.build()
);
To get items based on multiple content types, specify the content types' codenames using the
in
filter.// Gets items based on the types Article, Product, and News
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterIn("system.type", "article", "product", "news")
.build()
);
Filter by date & time and numbers
To get items by a datetime value, you can use one of the comparison filters. This lets you retrieve content modified or released before or after a certain date. The following code shows the filters used on the last content modification date and a date & time element.// Note: Date & time element values are provided by users and stored with minute precision. The system.last_modified value reflects Last content change to an item and is stored with ms precision.
// Gets items modified after April 9 2020, 9 am UTC+0
CompletionStage<ContentItemsListingResponse> items1 = client.getItems(
DeliveryParameterBuilder.params()
.filterGreaterThan("system.last_modified", "2020-05-09T09:00:00.000000Z")
.build()
);
// Gets items released at or after April 9 2020, 7 am UTC+0
CompletionStage<ContentItemsListingResponse> items2 = client.getItems(
DeliveryParameterBuilder.params()
.filterGreaterThanEquals("system.release_date", "2020-05-09T07:00:00Z")
.build()
);
// Gets items modified before April 5 2020 UTC+0. Last match would be at 2020-05-04T23:59:59.
CompletionStage<ContentItemsListingResponse> items3 = client.getItems(
DeliveryParameterBuilder.params()
.filterLessThan("system.last_modified", "2020-05-05")
.build()
);
// Gets items released at or before April 5 2020 10:30 am UTC+0
CompletionStage<ContentItemsListingResponse> items4 = client.getItems(
DeliveryParameterBuilder.params()
.filterLessThanEquals("system.release_date", "2020-05-05T10:30:00Z")
.build()
);
Tip: Use the same approach for number elements.
Filter by a range of dates and numbers
To get items based on a date range, you need to specify two datetime values using the
range
filter.
To get items based on a number range, you need to specify two numbers. The numbers can be either integers like
3
or floats like 3.14
.
Filter by text and rich text
To get items based on the value of a text or rich text element, you need to specify the value using the equals filter. The same approach also applies to custom elements.
// Gets items whose Title element value equals to "Hello World"
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterEquals("elements.title", "Hello World")
.build()
);
Filter by taxonomy and multiple choice
To get items tagged with specific taxonomy terms, you need to specify the terms using the
contains
, any
, or all
filters.// Note: Filters work with codenames of the tags.
// Gets items tagged with one specific tag
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterContains("elements.tags", "kontent_ai")
.build()
);
// Gets items tagged with a list of specific tags
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterAll("elements.tags", "kontent_ai", "cms")
.build()
);
// Gets items tagged with at least one of multiple tags
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterAny("elements.tags", "headless", "cms")
.build()
);
Filter by URL slug
The URL slug element value is stored in the same way as the values of text elements. This means the approach to getting items by a specific URL slug is the same, using theequals
filter.
// Gets items in default language with the URL slug element equal to 'sample-url-slug'
CompletionStage<ContentItemsListingResponse> items = client.getItems(
DeliveryParameterBuilder.params()
.filterEquals("elements.url_slug", "sample-url-slug")
.build()
);
language
parameter in your requests.
Filter by parent items
Sign in with your Kontent.ai credentials or sign up for free to unlock the full lesson, track your progress, and access exclusive expert insights and tips!