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

Get content from your project

Is this page helpful?
Complete and continue
  • Sign in
    • JavaScript
      JavaScript
    • TypeScript
      TypeScript
    • .NET
      .NET
    • Java
      Java
    • PHP
      PHP
    • Ruby
      Ruby
    • REST
      REST
    Jan Cerman
    11 minutes
    Delivery API / Content items
    Getting content from your project is one of the core responsibilities of your app.Discover how to use basic filtering to retrieve some of your project’s published content items, such as articles.

    Which API to use?

    While your content creators write articles and add finishing touches to the content in your project, you can display that content in web and mobile apps using Delivery API. Delivery API is a read-only API that’s available as both REST API and GraphQL API. Here you’ll learn the basics of using the Delivery REST API for getting published content.

    Make a request

    To retrieve content items from a project, you need to specify the project’s environment ID. You can find your environment ID in the environment settings. Let’s see how to get all content items from the specified environment.
    Recently published content items may appear in the API after a slight delay.

    Filter items by type

    You know how to retrieve all items. Let’s expand by retrieving items based on a specific type. In this example, you’ll retrieve items based on the Article content type.

    1. Find the codename

    Before moving further, you need to find the codename of the content type.
    You can copy codenames by clicking Codename near the name of a content type, content element, or other objects in your project. For example, to find the codename of the Article content type, go to Content model > Content types > Article > Codename.
    Once you have the codename, use it to filter the requested content items by their type.

    2. Filter by type’s codename

    The information about a content item’s type is stored in the content item’s System object property. The System object contains metadata about the content item, such as the last content modification date, language, content type, and more.
    To retrieve content items by type, you need to filter them by the value of their type property. Any content items not based on the Article content type will be omitted from the API response.

    Order the items

    By default, the Delivery API sorts content items alphabetically by their codenames. With content like articles, you might want to use chronological order. For example, have the articles ordered by their last modified date. To retrieve content items in a specific order, specify the following:
    • Which content item property to order by. For example, the property can be an element (such as text or date & time element) or metadata (such as the item’s type or last modified date).
    • Whether to use the ascending or descending order.
    With basic filtering and sorting skills under your belt, you’ve learned how to get specific content items from your Kontent.ai project.
    What's next?
    Ways to get localized content
    If you plan to display culture-specific content, your app needs to know how to retrieve content in specific languages.Depending on what you know about your content, there are a few ways to go about this.
    • Develop with Kontent.ai
    • Hello World
    • Hello Web Spotlight
    • Run a sample app
    • Build apps
    • Decide navigation and URLs
    • Environments
    • Get Developer Certification
    • JSON
    Displaying the codename of the Article content type.
    {
      "system": {
        "id": "335d17ac-b6ba-4c6a-ae31-23c1193215cb",
        "collection": "default",
        "name": "My article",
        "codename": "my_article",
        "language": "en-US",
        "type": "article",
        "sitemap_locations": [],
        "last_modified": "2023-03-27T13:21:11.38Z",
        "workflow_step": "published"
      },
      "elements": {
        ...
      }
    }
    • Quickstart
    • Get content
    • Get localized content
    • Use the right filters
    • C#
    • C#
    • C#
    Paging the resultsIf you don’t need all content items at once, you can play with the paging by specifying the limit and skip parameters. For example, setting the limit to 3 and skip to 6 gives you the third page of results.
    Quick facts about codenamesCodenames are alphanumeric identifiers of objects in Kontent.ai. Codenames are initially generated from the object’s name, such as the content item name.
    // Tip: Find more about .NET SDKs at https://kontent.ai/learn/net
    using Kontent.Ai.Delivery;
    
    // Creates an instance of the delivery client
    // ProTip: Use DI for this in your apps https://kontent.ai/learn/net-register-client
    IDeliveryClient client = DeliveryClientBuilder
          .WithProjectId("8d20758c-d74c-4f59-ae04-ee928c0816b7")
          .Build();
    
    // Gets all content items
    // Note: Using the <object> generic parameter produces strongly typed objects, based on "system.type"
    IDeliveryItemListingResponse<object> response = await client.GetItemsAsync<object>();
    
    IList<object> items = response.Items;
    // Tip: Find more about .NET SDKs at https://kontent.ai/learn/net
    using Kontent.Ai.Delivery;
    
    // Creates an instance of the delivery client
    // ProTip: Use DI for this in your apps https://kontent.ai/learn/net-register-client
    IDeliveryClient client = DeliveryClientBuilder
          .WithProjectId("8d20758c-d74c-4f59-ae04-ee928c0816b7")
          .Build();
    
    // Gets all articles
    // Create strongly typed models according to https://kontent.ai/learn/net-strong-types
    IDeliveryItemListingResponse<Article> response = await client.GetItemsAsync<Article>(
        new EqualsFilter("system.type", "article")
    );
    
    IList<Article> items = response.Items;
    // Tip: Find more about .NET SDKs at https://kontent.ai/learn/net
    using Kontent.Ai.Delivery;
    
    // Creates an instance of the delivery client
    // ProTip: Use DI for this in your apps https://kontent.ai/learn/net-register-client
    IDeliveryClient client = DeliveryClientBuilder
          .WithProjectId("8d20758c-d74c-4f59-ae04-ee928c0816b7")
          .Build();
    
    // Gets the 3 latest articles ordered by their last modified time
    // Create strongly typed models according to https://kontent.ai/learn/net-strong-types
    IDeliveryItemListingResponse<Article> response = await client.GetItemsAsync<Article>(
        new EqualsFilter("system.type", "article"),
        new LimitParameter(3),
        new OrderParameter("system.last_modified", SortOrder.Descending)
    );
    
    IList<Article> items = response.Items;
  • Which API to use?
  • Make a request
  • Filter items by type
  • Order the items