Get content from your project
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.<?php
// Tip: Find more about PHP SDKs at https://kontent.ai/learn/php
// Defined by Composer to include required libraries
require __DIR__ . '/vendor/autoload.php';
use Kontent\Ai\Delivery\DeliveryClient;
$client = new DeliveryClient('8d20758c-d74c-4f59-ae04-ee928c0816b7');
$items = $client->getItems();
?>
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.
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.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.
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.{
"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": {
...
}
}
type
property. Any content items not based on the Article content type will be omitted from the API response.
<?php
// Tip: Find more about PHP SDKs at https://kontent.ai/learn/php
// Defined by Composer to include required libraries
require __DIR__ . '/vendor/autoload.php';
use Kontent\Ai\Delivery\DeliveryClient;
$client = new DeliveryClient('8d20758c-d74c-4f59-ae04-ee928c0816b7');
$items = $client->getItems((new QueryParams())
->equals('system.type', 'article'));
?>
Order the 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!