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 codenames of a single type and want to retrieve the items in a single request, use GraphQL aliases.
    To get items based on a single content type, use the root collection query for a specific type, for example, product_All.
    To get items based on multiple content types, specify multiple root collection queries.
    The Delivery GraphQL API doesn't support filtering content items based on a range of values. See the list of supported filters.
    To get items tagged with specific taxonomy terms, you need to specify the terms using either the containsAny or containsAll filters.
    • Quickstart
    • Get content
    • Get localized content
    • Use the right filters
    • GraphQL
    • GraphQL
    • GraphQL
    • GraphQL
    • GraphQL
    • GraphQL
    • GraphQL
    • GraphQL
    • GraphQL
    • GraphQL
    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
    query GetArticleById {
      article_All(where: {_system_: {id: {eq: "2f7288a1-cfc8-47be-9bf1-b1d312f7da18"}}}) {
        items {
          title
        }
      }
    }
    # Gets three articles by their codenames. Use GraphQL aliases to retrieve multiple items of the same type.
    query GetArticlesByCodenames {
      helloWorldArticle: article(codename: "hello_world") {
        title
      }
      getContentArticle: article(codename: "get_content") {
        title
      }
      filterContentArticle: article(codename: "filter_content") {
        title
      }
    }
    # Gets items based on the type Product
    query GetItemsByType {
        product_All { # Root collection query specifies the content type
            items {
                price
            }
        }
    }
    # Gets items based on the types Product, Article, and News
    query GetItemsByTypes {
        product_All { # Root collection query for Product means you'll get items based on the Product content type
            items {
                name
            }
        }
        article_All { # Root collection query for Article means you'll get items based on the Article content type
            items {
                title
            }
        }
        news_All { # Root collection query for News means you'll get items based on the News content type
            items {
                title
            }
        }
    }
    # Gets articles modified after November 1 2021, 9 am UTC+0
    query GetArticlesModifiedAfterDate {
      article_All (where: {_system_: {lastModified: {gt: "2021-11-01T09:00:00Z"}}}) {
        items {
          title
        }
      }
    }
    
    # Gets articles released at or after November 1 2021, 9 am UTC+0
    query GetArticlesReleasedAfterDate {
      article_All (where: {releaseDate: {gte: "2021-11-01T09:00:00Z"}}) {
        items {
          title
        }
      }
    }
    
    # Gets articles modified before November 1 2021, 12 pm UTC+0. Last match would be at 2021-10-31T:11:59:59
    query GetArticlesModifiedBeforeDate {
      article_All (where: {_system_: {lastModified: {lt: "2021-11-01T00:00:00Z"}}}) {
        items {
          title
        }
      } 
    }
    
    # Gets articles released at or before November 1 2021, 9 am UTC+0
    query GetArticlesReleasedAfterDate {
      article_All (where: {releaseDate: {lte: "2021-11-01T09:00:00Z"}}) {
        items {
          title
        }
      }
    }
    # Gets articles whose Title element value equals to "Hello World"
    query GetArticleByTitle {
      article_All(where: {title: {eq: "Hello World"}}) {
        items {
          title
        }
      }
    }
    # Note: Filters work with codenames. This means codenames of the taxonomy terms or multiple choice options.
    # Gets items tagged with one specific tag
    query GetArticlesTaggedWithATerm {
      article_All(where: {topic: {containsAny: ["kontent_ai"]}}) {
        items {
          title
        }
      }
    }
    
    # Gets items tagged with a list of specific tags
    query GetArticlesTaggedWithTerms {
      article_All(where: {topic: {containsAll: ["kontent_ai", "cms"]}}) {
        items {
          title
        }
      }
    }
    
    # Gets items tagged with at least one tag from the list
    query GetArticlesTaggedWithOneOfTerms {
      article_All(where: {topic: {containsAny: ["headless", "cms"]}}) {
        items {
          title
        }
      }
    }
    # Gets items whose URL slug equals to sample-url-slug
    query GetArticlesByUrlSlug {
      article_All(where: {url: {eq: "sample-url-slug"}}) {
        items {
          title
        }
      }
    }
    # Gets items attributed to Jane.
    query GetArticlesByAuthor {
      article_All(where: {author: {containsAll: ["jane_doe"]}}) {
        items {
          title
        }
      }
    }
    
    # Gets items attributed to at least Jane, John, or both.
    query GetArticlesByOneOfAuthors {
      article_All(where: {author: {containsAny: ["jane_doe", "john_wick"]}}) {
        items {
          title
        }
      }
    }
    # Gets pages linking travel insurance as their subpage.
    query GetArticlesTaggedWithATerm {
      article_All(where: {subpages: {containsAll: ["travel_insurance"]}}) {
        items {
          title
        }
      }
    }
    
    # Gets pages linking at least travel insurance, car insurance, or both as their subpage.
    query GetArticlesTaggedWithTerms {
      article_All(where: {subpages: {containsAny: ["travel_insurance", "car_insurance"]}}) {
        items {
          title
        }
      }
    }
  • 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
  • Also works for multiple choice elementsUse the same approach to get items based on a specific value or values of multiple choice elements.