PHPackages                             kontent-ai/delivery-sdk-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. kontent-ai/delivery-sdk-php

AbandonedArchivedLibrary[API Development](/categories/api)

kontent-ai/delivery-sdk-php
===========================

Kontent.ai Delivery SDK for PHP

6.0.3(2y ago)4633.0k↓53.4%13[12 issues](https://github.com/kontent-ai/delivery-sdk-php/issues)[1 PRs](https://github.com/kontent-ai/delivery-sdk-php/pulls)1MITPHPPHP ^7.0 || ^8.0CI failing

Since Nov 2Pushed 2mo ago20 watchersCompare

[ Source](https://github.com/kontent-ai/delivery-sdk-php)[ Packagist](https://packagist.org/packages/kontent-ai/delivery-sdk-php)[ Docs](https://kontent.ai/)[ RSS](/packages/kontent-ai-delivery-sdk-php/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (4)Versions (27)Used By (1)

Warning

**This SDK has been archived and is no longer maintained.**

No further updates, bug fixes, security patches, or support will be provided. The SDK is available as-is for legacy projects, but its use in new implementations is not recommended.

Kontent.ai Delivery SDK for PHP
===============================

[](#kontentai-delivery-sdk-for-php)

[![Build & Test & Report](https://github.com/kontent-ai/delivery-sdk-php/actions/workflows/integrate.yml/badge.svg)](https://github.com/kontent-ai/delivery-sdk-php/actions/workflows/integrate.yml)[![Packagist](https://camo.githubusercontent.com/077ba80b7c23e9493df2325cd06f25c8326287755bd932f1ec00360e8aaabdc9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b6f6e74656e742d61692f64656c69766572792d73646b2d7068702e737667)](https://packagist.org/packages/kontent-ai/delivery-sdk-php)[![codecov](https://camo.githubusercontent.com/7c78de99de7035c103dfce1939744184ec1f9f342017154de1e347de3caef3a6/68747470733a2f2f636f6465636f762e696f2f67682f6b6f6e74656e742d61692f64656c69766572792d73646b2d7068702f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/kontent-ai/delivery-sdk-php)[![Stack Overflow](https://camo.githubusercontent.com/276c1a797a2daa70b56a2736f7fdbbe312543df9ef3511f0119948a8af0edec5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f537461636b2532304f766572666c6f772d41534b2532304e4f572d4645374131362e7376673f6c6f676f3d737461636b6f766572666c6f77266c6f676f436f6c6f723d7768697465)](https://stackoverflow.com/tags/kontent-ai)[![Discord](https://camo.githubusercontent.com/02ea8c52a130f8b682bd5272c4e77f3f1953f4f87a8640f811f6385af246f3e7/68747470733a2f2f696d672e736869656c64732e696f2f646973636f72642f3832313838353137313938343839313931343f636f6c6f723d253233373238394441266c6162656c3d4b6f6e74656e742e6169253230446973636f7264266c6f676f3d646973636f7264)](https://discord.gg/SKCxwPtevJ)

Summary
-------

[](#summary)

The Kontent.ai Delivery PHP SDK is a client library used for retrieving content from Kontent.ai. The best way to use the SDK is to consume it in the form of a [Packagist package](https://packagist.org/packages/kontent-ai/delivery-sdk-php). The library currently supports only PHP 8 and above.

Sample site
-----------

[](#sample-site)

Check out a sample site running on Laravel utilizing this SDK here:

Installation
------------

[](#installation)

The best way to install the client is through a dependency manager called [Composer](https://getcomposer.org/):

```
composer require kontent-ai/delivery-sdk-php
```

or adjusting your `composer.json` file:

```
{
    "require": {
        "kontent-ai/delivery-sdk-php": "^6.0.0"
    }
}
```

### Autoloading

[](#autoloading)

Writing object-oriented applications requires one PHP source file per class definition. One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class).

Since the SDK uses [Composer](https://getcomposer.org/) dependency manager and specifies autoload information, Composer generates a [vendor/autoload.php](https://getcomposer.org/doc/01-basic-usage.md#autoloading) file. You can simply include this file and start using the namespaces that those libraries offer without any extra work:

```
require __DIR__ . '/vendor/autoload.php';
```

Using the DeliveryClient
------------------------

[](#using-the-deliveryclient)

The `DeliveryClient` class is the main class of the SDK. Using this class, you can retrieve content from your Kontent.ai projects.

To create an instance of the class, you need to provide a [project ID](https://kontent.ai/learn/tutorials/develop-apps/get-content/get-content-items#a-1-find-your-project-id).

```
use Kontent\Ai\Delivery\DeliveryClient;

// Initializes an instance of the DeliveryClient client
$client = new DeliveryClient('975bf280-fd91-488c-994c-2f04416e5ee3');
```

There are some other optional parameters that you can use during the `DeliveryClient` instantiation.

- `$previewApiKey` – sets the Delivery Preview API key. The client will automatically start using the preview endpoint for querying. See [previewing unpublished content](#previewing-unpublished-content).
- `$securedProductionApiKey` – sets the production Delivery API key (do not combine it with the Delivery Preview API key)
- `$waitForLoadingNewContent` – makes the client instance wait while fetching updated content, useful when acting upon [webhook calls](https://kontent.ai/learn/tutorials/develop-apps/integrate/webhooks#a-get-the-latest-content).
- `$debugRequests` – switches the HTTP client to debug mode
- `$retryAttempts` – number of times the client will retry to connect to the Kontent.ai API on failures per request

Once you create a `DeliveryClient`, you can start querying your project repository by calling methods on the client instance. See [Basic querying](#basic-querying) for details.

Basic querying
--------------

[](#basic-querying)

Once you have a `DeliveryClient` instance, you can start querying your project repository by calling methods on the instance.

```
// Retrieves a single content item
$item = $client->getItem('about_us');

// Retrieves a list of all content items
$items = $client->getItems();
```

### Filtering retrieved data

[](#filtering-retrieved-data)

The SDK supports full scale of the API querying and filtering capabilities as described in the [API reference](https://kontent.ai/learn/reference/delivery-api#tag/Filtering-content).

```
use Kontent\Ai\Delivery\QueryParams;

// Retrieves a list of the specified elements from the first 10 content items of
// the 'brewer' content type, ordered by the 'product_name' element value
$response = $client->getItems((new QueryParams())
  ->equals('system.type', 'brewer')
  ->elements(array('image', 'price', 'product_status','processing'))
  ->limit(10)
  ->orderAsc('elements.product_name'));
```

### Getting localized items

[](#getting-localized-items)

The language selection is just a matter of specifying one additional filtering parameter to the query.

```
use Kontent\Ai\Delivery\QueryParams;

// Retrieves a list of the specified elements from the first 10 content items of
// the 'brewer' content type, ordered by the 'product_name' element value
$response = $client->getItems((new QueryParams())
  ->language('es-ES')
  ->equals('system.type', 'brewer')
  ->elements(array('image', 'price', 'product_status','processing'))
  ->limit(10)
  ->orderAsc('elements.product_name'));
```

### Working with taxonomies

[](#working-with-taxonomies)

To retrieve information about your taxonomies, you can use the `getTaxonomy` and `getTaxonomies` methods. Additionally, you can specify query [parameters](https://kontent.ai/learn/reference/delivery-api#operation/list-taxonomy-groups).

```
use Kontent\Ai\Delivery\QueryParams;

// Retrieves a list of the specified taxonomy groups.
$response = $client->getTaxonomies((new QueryParams())
  ->limit(3);

// Retrieves a specific taxonomy group.
$response = $client->getTaxonomy('persona');
```

Previewing unpublished content
------------------------------

[](#previewing-unpublished-content)

To retrieve unpublished content, you need to create a `DeliveryClient` with both Project ID and Preview API key. Each Kontent.ai project has its own Preview API key.

```
// Note: Within a single project, we recommend that you work with only
// either the production or preview Delivery API, not both.
$client = new DeliveryClient('YOUR_PROJECT_ID', 'YOUR_PREVIEW_API_KEY');
```

For more details, see [Previewing unpublished content using the Delivery API](https://kontent.ai/learn/tutorials/develop-apps/build-strong-foundation/set-up-preview#a-get-the-latest-version-of-everything).

Response structure
------------------

[](#response-structure)

For full description of single and multiple content item JSON response formats, see our [API reference](https://kontent.ai/learn/reference/delivery-api#operation/list-content-items).

### Single content item response

[](#single-content-item-response)

When retrieving a single content item, you get an instance of the `ContentItem` class. This class contains a 'system' property (with metadata about the content item, such as code name, display name, type, collection, or sitemap location) and respective content item's elements projected as [camelCase](https://en.wikipedia.org/wiki/Camel_case) properties.

[![Single item](./assets/single-item-response.png)](./assets/single-item-response.png)

### Multiple content items response

[](#multiple-content-items-response)

When retrieving a list of content items, you get an instance of the `ContentItemsResponse`. This class represents the JSON response from the Delivery API endpoint and contains:

- `Pagination` property with information about the following:
    - `Skip`: requested number of content items to skip
    - `Limit`: requested page size
    - `Count`: the total number of retrieved content items
    - `NextPageUrl`: the URL of the next page
- An array of the requested [content items](#single-content-item-response)

### Properties and their types

[](#properties-and-their-types)

- All properties are named in the [camelCase](https://en.wikipedia.org/wiki/Camel_case) style.
- If a property contains a collection of objects, it's typed as an array which is indexed by:
    - codenames, if the contained entities have a code name
    - numbers, if they don't have code names. We use zero-based indexing.
- If a property references linked items (property is of the linked item type), the references are replaced with the respective [content items](#single-content-item-response) themselves.
- If a property is of asset, multiple choice option, or taxonomy group type, it's resolved to respective well-known models from the `Kontent\Ai\Delivery\Models\Items` namespace.
- All timestamps are typed as `\DateTime`.
- All numbers are typed as `float`.

### Mapping custom models

[](#mapping-custom-models)

It's possible to instruct the SDK to fill and return your own predefined models. To do that you have to implement:

- `TypeMapperInterface` (required) - to provide mapping of Kontent.ai content types to your models
- `PropertyMapperInterface` (optional) - to change the default behavior of property mapping (the default property translation works like this: 'content\_type' -&gt; 'contentType')
- `ValueConverterInterface` (optional) - to change the way content element types are mapped to PHP types
- `ContentLinkUrlResolverInterface` (optional) - to change the way the links in Rich text elements are resolved see [Resolving links to content items](./wiki/Resolving-links-to-content-items.md).
- `InlineLinkedItemsResolverInterface` (optional) - to change the way content items in Rich text elements are resolved see [Resolving content items and components in Rich text](./wiki/Resolving-content-items-and-components-in-Rich-text.md).

The default implementation of all the interfaces can be found in a class called [`DefaultMapper`](./src/Kontent/Ai/Delivery/DefaultMapper.php).

Example:

```
class TetsMapper extends DefaultMapper
{
    public function getTypeClass($typeName)
    {
        switch ($typeName) {
            case 'home':
                return \Kontent\Ai\Tests\E2E\HomeModel::class;
            case 'article':
                return \Kontent\Ai\Tests\E2E\ArticleModel::class;
        }

        return parent::getTypeClass($typeName);
    }
}
...

public function testMethod()
{
    $client = new DeliveryClient('975bf280-fd91-488c-994c-2f04416e5ee3');
    $client->typeMapper = new TetsMapper();
    $item = $client->getItem('on_roasts');
    $this->assertInstanceOf(\Kontent\Ai\Tests\E2E\ArticleModel::class, $item); // Passes
}
```

The `ArticleModel` can then look like this (and contain only the properties you need to work with):

```
class ArticleModel
{
    public $system = null;
    public $title = null;
    public $urlPattern = null;
}
```

Feedback &amp; Contributing
---------------------------

[](#feedback--contributing)

Check out the [contributing](./CONTRIBUTING.md) page to see the best places to file issues, start discussions, and begin contributing.

1. Clone the repository
2. Run `composer install` to install dependencies
3. Run `phpunit` to verify that everything works as expected

### Developing on Windows

[](#developing-on-windows)

Have a look at our cool [tutorial](./wiki/Developing-PHP-in-Visual-Studio-Code-for-Dummies.md) on developing PHP on Windows with Visual Studio Code!

### Developing on Linux

[](#developing-on-linux)

Do you prefer penguins? Check out our [tutorials](./wiki/Configuring-PHP-Storm-on-Linux.md) on developing PHP on Linux with PhpStorm!

### Wall of Fame

[](#wall-of-fame)

We would like to express our thanks to the following people who contributed and made the project possible:

- [Stephen Rushing](https://github.com/stephenr85/) - [eSiteful](http://www.esiteful.com/home) - [ORIGINAL WORK](https://github.com/stephenr85/KenticoCloud.Deliver.PHP)

Would you like to become a hero too? Pick an [issue](https://github.com/kontent-ai/delivery-sdk-php/issues) and send us a pull request!

###  Health Score

53

—

FairBetter than 96% of packages

Maintenance53

Moderate activity, may be stable

Popularity42

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 61.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~101 days

Recently: every ~218 days

Total

25

Last Release

774d ago

Major Versions

1.2.0 → 2.0.02018-10-08

2.0.1 → 3.0.02019-09-17

3.2.0-beta1 → 4.0.02021-11-23

4.0.0 → 5.0.02022-02-11

5.0.0 → 6.0.02022-09-19

PHP version history (2 changes)0.0.1PHP ^7.0

5.0.0PHP ^7.0 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9f0ec48d933d2688f0edf108090132212c199cfeb1b4e84ca3d1d36fc65dd877?d=identicon)[kontent-ai](/maintainers/kontent-ai)

---

Top Contributors

[![petrsvihlik](https://avatars.githubusercontent.com/u/9810625?v=4)](https://github.com/petrsvihlik "petrsvihlik (205 commits)")[![Simply007](https://avatars.githubusercontent.com/u/9218736?v=4)](https://github.com/Simply007 "Simply007 (90 commits)")[![dusekdan](https://avatars.githubusercontent.com/u/6360711?v=4)](https://github.com/dusekdan "dusekdan (16 commits)")[![jankonas](https://avatars.githubusercontent.com/u/7345659?v=4)](https://github.com/jankonas "jankonas (12 commits)")[![jancerman](https://avatars.githubusercontent.com/u/8464629?v=4)](https://github.com/jancerman "jancerman (2 commits)")[![NoodlesNZ](https://avatars.githubusercontent.com/u/1063979?v=4)](https://github.com/NoodlesNZ "NoodlesNZ (1 commits)")[![pokornyd](https://avatars.githubusercontent.com/u/52500882?v=4)](https://github.com/pokornyd "pokornyd (1 commits)")[![tspencer244](https://avatars.githubusercontent.com/u/15922667?v=4)](https://github.com/tspencer244 "tspencer244 (1 commits)")[![hisman](https://avatars.githubusercontent.com/u/1266907?v=4)](https://github.com/hisman "hisman (1 commits)")[![JanLenoch](https://avatars.githubusercontent.com/u/17413329?v=4)](https://github.com/JanLenoch "JanLenoch (1 commits)")[![juraju-kentico](https://avatars.githubusercontent.com/u/25588393?v=4)](https://github.com/juraju-kentico "juraju-kentico (1 commits)")[![Mosnar](https://avatars.githubusercontent.com/u/3810939?v=4)](https://github.com/Mosnar "Mosnar (1 commits)")

---

Tags

composerdelivery-apihacktoberfestheadless-cmskontent-aikontent-ai-samplepackagistphpphp7cmsheadlessdeliveryheadless cmscontent-deliverykontent-ai

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kontent-ai-delivery-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/kontent-ai-delivery-sdk-php/health.svg)](https://phpackages.com/packages/kontent-ai-delivery-sdk-php)
```

###  Alternatives

[getkirby/kql

Kirby Query Language

15028.4k](/packages/getkirby-kql)[riclep/laravel-storyblok

A Laravel wrapper around the Storyblok API to provide a familiar experience for Laravel devs

6281.2k5](/packages/riclep-laravel-storyblok)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
