Kontent.ai
Copyright © 2023 Kontent.ai. All rights reserved.
  • Web
  • Privacy policy
  • Cookies policy
  • Consent settings
  • Security
  • GDPR
  • Documentation
  • API reference
  • Product updates
Kontent.ai Learn
  • Plan
  • Set up
  • Model
  • Develop
  • Create

Filter content to get what you need

Is this page helpful?
Complete and continue
  • Sign in
    • JavaScript
      JavaScript
    • TypeScript
      TypeScript
    • .NET
      .NET
    • Java
      Java
    • PHP
      PHP
    • Ruby
      Ruby
    • REST
      REST
    • GraphQL
      GraphQL
    Jan Cerman
    35 minutes
    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 in system.id) against the ID value you have.

    Filter by content types

    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.

    Filter by a range of dates and numbers

    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.

    Filter by taxonomy and multiple choice

    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 the equals filter.
    To ensure you get content in a specific language, use the language parameter in your requests.

    Filter by relationships, such as an article’s author

    When you link multiple items together you might want to retrieve your items based on their relationships. For example, you can have several articles written by a single author, Jane. Each article has a linked items element named Author. This element contains a reference to a content item that represents the author Jane. The reference in the Author element is stored as a codename of the Jane content item.

    Filter by subpages

    When using Web Spotlight to manage your website content, you can retrieve subpages the same way as your linked items. For example, you can have various insurance-related pages linked in multiple places on your website.
    What's next?
    First steps with Web Spotlight
    Time to set up your project for Web Spotlight! You’ll get to know what Web Spotlight looks like, how to activate it, and how to create a page tree.
    • Develop with Kontent.ai
    • Hello World
    • Hello Web Spotlight
    • Run a sample app
    • Build apps
    • Decide navigation and URLs
    • Environments
    • Get Developer Certification
    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.
    To get items based on a single content type, specify the content type's codename (system.type) using the equals filter.
    To get items based on multiple content types, specify the content types' codenames using the in filter.
     The same approach also applies to custom elements.
    To get items tagged with specific taxonomy terms, you need to specify the terms using the contains, any, or all filters.
    • Quickstart
    • Get content
    • Get localized content
    • Use the right filters
    • TypeScript
    • TypeScript
    • TypeScript
    • TypeScript
    • TypeScript
    • TypeScript
    • TypeScript
    • TypeScript
    • TypeScript
    • TypeScript
    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.
    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.
    Tip: Use the same approach for number elements.
    // Gets an item by its internal ID
    const response = await deliveryClient.items()
      .equalsFilter('system.id', '2f7288a1-cfc8-47be-9bf1-b1d312f7da18')
      .toPromise();
    // Gets three items by their codenames. The codenames are unique per project.
    const response = await deliveryClient.items()
      .inFilter('system.codename', ['delivery_api', 'get_content', 'hello_world'])
      .toPromise();
    // Gets items based on the type Product
    const response = await deliveryClient.items()
      .equalsFilter('system.type', 'product') // Same as using .type('product')
      .toPromise();
    // Gets items based on the types Product, Article, and News
    const response = await deliveryClient.items()
      .inFilter('system.type', ['product', 'article', 'news'])
      .toPromise();
    // 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
    const response = await deliveryClient.items()
      .greaterThanFilter('system.last_modified', '2020-05-09T09:00:00.000000Z')
      .toPromise();
    
    // Gets items released at or after April 9 2020, 7 am UTC+0
    const response = await deliveryClient.items()
      .greaterThanOrEqualFilter('elements.release_date', '2020-05-09T07:00:00Z')
      .toPromise();
    
    // Gets items modified before April 5 2020 UTC+0. Last match would be at 2020-05-04T23:59:59.
    const response = await deliveryClient.items()
      .lessThanFilter('system.last_modified', '2020-05-05')
      .toPromise();
    
    // Gets items released at or before April 5 2020 10:30 am UTC+0
    const response = await deliveryClient.items()
      .lessThanOrEqualFilter('elements.release_date', '2020-05-05T10:30:00Z')
      .toPromise();
    // Gets items whose Title element value equals to 'Hello World'
    const response = await deliveryClient.items()
      .equalsFilter('elements.title', 'Hello World')
      .toPromise();
    // Note: Filters work with codenames of the tags.
    // Gets items tagged with one specific tag
    const response = await deliveryClient.items()
      .containsFilter('elements.tags', ['kontent_ai'])
      .toPromise();
    
    // Gets items tagged with a list of specific tags
    const response = await deliveryClient.items()
      .allFilter('elements.tags', ['kontent_ai', 'cms'])
      .toPromise();
    
    // Gets items tagged with at least one tag from the list
    const response = await deliveryClient.items()
      .anyFilter('elements.tags', ['headless', 'cms'])
      .toPromise();
    // Gets items whose URL slug equals to sample-url-slug
    const response = await deliveryClient.items()
      .equalsFilter('elements.url_slug', 'sample-url-slug')
      .toPromise();
    // Gets items attributed to Jane.
    const response = await deliveryClient.items()
      .containsFilter('elements.author', ['jane_doe'])
      .toPromise();
    
    // Gets items attributed to at least Jane, John, or both.
    const response = await deliveryClient.items()  
      .anyFilter('elements.author', ['jane_doe', 'john_wick'])
      .toPromise();
    // Gets pages linking travel insurance as their subpage.
    const response = await deliveryClient.items()
      .containsFilter('elements.subpages', ['travel_insurance'])
      .toPromise();
    
    // Gets pages linking at least travel insurance, car insurance, or both as their subpage.
    const response = await deliveryClient.items()
      .anyFilter('elements.subpages', ['travel_insurance', 'car_insurance'])
      .toPromise();
  • Filter by item ID or a codename
  • Filter by content types
  • Filter by date & time and numbers
  • Filter by a range of dates and numbers
  • Filter by text and rich text
  • Filter by taxonomy and multiple choice
  • Filter by URL slug
  • Filter by relationships, such as an article’s author
  • Filter by subpages
    • TypeScript
    • TypeScript
    If you know the item's codename, we recommend you retrieve the content item directly for better performance.
    Also works for the multiple choice and custom elementsUse the same approach to get items based on a specific value or values of the multiple choice elements. For custom elements, the contains, any, and all filters work only if the element’s value is a stringified array of strings. For example, "[\"DE\",\"US\",\"UK\"]".
    // 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 between April 5, 2020 10:30 UTC and April 7, 2020, 7:00 UTC
    const response = await deliveryClient.items()
      .rangeFilter('system.last_modified', '2020-05-05T10:30:00', '2020-05-07T07:00:00')
      .toPromise();
    // Gets items whose rating is at least 6.5 and at most 9
    const response = await deliveryClient.items()
      .rangeFilter('elements.product_rating', '6.5', '9')
      .toPromise();