---
title: "Contentstack Delivery PHP SDK"
description: "Documentation for PHP Delivery SDK"
url: "https://www.contentstack.com/docs/developers/sdks/content-delivery-sdk/php/reference"
product: "Contentstack"
doc_type: "guide"
audience:
  - developers
  - admins
version: "current"
last_updated: "2025-09-15"
---

# Contentstack Delivery PHP SDK

## Contentstack - PHP Delivery SDK

## PHP SDK for Contentstack's Content Delivery API

Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. [Read More](https://www.contentstack.com/).

## Prerequisites

To get started with PHP, you will need the following:

*   PHP version 5.5.0 or later

## SDK installation and setup

To install the PHP SDK, choose either of the following methods:

#### **Method 1: Using Composer**

To install the PHP SDK in your project using [Composer](https://packagist.org/packages/contentstack/contentstack), fire up the terminal, point it to the project location, and run the following command:

composer require contentstack/contentstack

#### **Method 2: Downloading the zip file**

To download the PHP SDK, perform the following steps:

1.  [Download](https://www.contentstack.com/docs/developers/sdks/content-delivery-sdk/php/download) the PHP SDK.
2.  Create the dependencies folder in your project directory and move the downloaded .zip file within the dependencies folder.
3.  Download the [MabeEnum](https://github.com/marc-mabe/php-enum) class.
4.  Create a folder named marc-mabe folder inside dependencies, and move the php-enum folder to marc-mabe.

Let's get started with the implementation.

## Quickstart in 5 mins

## Initialize SDK

Initialize the SDK by following either of the methods depending on the type of installation.

**Method 1: If installed using Composer**

To initialize the SDK, specify the [API Key](https://www.contentstack.com/docs/developers/set-up-stack/view-stack-details/), [delivery token](https://www.contentstack.com/docs/developers/create-tokens/about-delivery-tokens/), and [environment](https://www.contentstack.com/docs/developers/set-up-environments/about-environments/) name of your stack.

use Contentstack\\Contentstack;  
  
$stack = Contentstack::Stack('api\_key', 'delivery\_token', 'environment');

**Method 2: If installed using the zip file**

To initialize the SDK, specify the API key, delivery token, and environment name of your stack.

include\_once DIR . '/dependencies/contentstack/index.php';  
use Contentstack\\Contentstack;  
  
$stack = Contentstack::Stack('api\_key', 'delivery\_token', 'environment');

Once you have initialized the SDK, you can start getting content in your app.

Note: By default, the SDK uses the North American region. Configuration changes are not required for North American region users.

**To set the Europe (EU), Azure North America(Azure\_NA), Azure Europe (Azure\_EU), GCP North America (GCP\_NA), or GCP Europe (GCP\_EU) region, refer to the code below:**

use Contentstack\\Contentstack;  
$stack = Contentstack::Stack('api\_key', 'delivery\_token', 'environment', array('region' => ContentstackRegion.<<add\_your\_region>>));

**For Setting the Branch.**

If you want to initialize SDK in a particular branch use the code given below:

use Contentstack\\Contentstack;  
  
$stack = Contentstack::Stack('api\_key', 'delivery\_token', 'environment', array('region' => Contentstack::Region::<<add\_your\_region>>, "branch"=>"branch"));

## Basic Queries

Contentstack SDKs let you interact with the [Content Delivery APIs](https://www.contentstack.com/docs/developers/apis/content-delivery-api/) and retrieve content from Contentstack. They are read-only in nature. The SDKs fetch and deliver content from the nearest server via Fastly, our powerful and robust CDN.

### Get a Single Entry

To get a single [entry](https://www.contentstack.com/docs/content-managers/working-with-entries/about-entries/), you need to specify the [content type](https://www.contentstack.com/docs/developers/create-content-types/about-content-types/) and the UID of the entry:

use Contentstack\\Contentstack;  
  
$stack = Contentstack::Stack('api\_key', 'delivery\_token', 'environment');  
$result = $stack->ContentType('content\_type\_uid')->Entry('entry\_uid')->toJSON()->fetch();  
$result - entry object  

### Get Multiple Entries

To retrieve multiple entries of a content type, specify the content type uid. You can also specify search parameters to filter results:

use Contentstack\\Contentstack;  
  
$stack = Contentstack::Stack('api\_key', 'delivery\_token', 'environment');  
$result = $stack->ContentType('content\_type\_uid')->Query()->toJSON()->includeCount()->includeContentType()->find();  
$result\[0\] - array of entries  
$result\[1\] - content type  
$result\[2\] - count of the entries  

These were examples of some of the basic queries of the SDK.

**Note:**

*   Currently, the PHP SDK does not support multiple content types referencing in a single query. For more information on how to query entries and assets, refer the [Queries](https://www.contentstack.com/docs/developers/apis/content-delivery-api/#queries) section of our Content Delivery API documentation.
*   By default, the limit for response details per request is 100, with the maximum limit set at 250.

## Paginating Responses

In a single instance, the [Get Multiple Entries](https://www.contentstack.com/docs/developers/php/get-started-with-php-sdk/#get-multiple-entries) query will **retrieve only the first 100 items** of the specified content type. You can paginate and retrieve the rest of the items in batches using the **limit** parameters in subsequent requests.

use Contentstack\\Contentstack;  
  
$stack = Contentstack::Stack('api\_key', 'delivery\_token', 'environment');  
$result = $stack->ContentType('content\_type\_uid')->Query()->toJSON()->skip(20)->limit(20)->find();

## Contentstack

Contentstack abstract class to provide access to Stack Object

## Stack

Static method for the Stack constructor

API Key of your stack on Contentstack.

Delivery token of your stack on Contentstack.

Environment from where you want to fetch content.

## ContentstackRegion

**Fields**

Name

Description

EU

To specify the EU region.

US

To specify the US region.

AZURE\_NA

To specify the AZURE NA region

AZURE\_EU

To specify the AZURE\_EU region

GCP\_NA

To specify the GCP\_NA region

GCP\_EU

To specify the GCP\_EU region

## CSException

CSException CSException Class is used to wrap the REST API error

## getErrors

Returns error details of current exception

## getStatusCode

To get http status\_code of the current exception

Contentstack error message.

Contentstack Error code

API http status code

## Stack

Stack Class to initialize the provided parameter Stack

## ContentType

To initialize the ContentType object from where the content will be fetched/retrieved.

Valid content type uid relevant to configured stack

## Assets

Assets Class to initalize your Assets

valid asset uid relevent to configured stack

## ImageTrasform

ImageTrasform function is define for image manipulation with different

Image url on which we want to manipulate.

It is an second parameter in which we want to place different manipulation key and value in array form

## LivePreviewQuery

To set live preview token and content type uid.

Set live preview token and content type uid.

## getLastActivities

To get the last\_activity information of the configured environment from all the content types.

## setHost

To set the host on stack object

Host name/ipaddress from where the content to be fetched

## getHost

This function returns host.

## setProtocol

This function sets protocol.

Protocol type

## getProtocol

This function return protocol type.

## setPort

This function sets Port.

Port Number

## getPort

This function return Port.

## setAPIKEY

This function sets API Key.

Stack API key

## getAPIKEY

This function returns API Key.

## setDeliveryToken

This function sets Delivery Token.

Environment specific delivery token

## DeliveryToken

This function returns Delivery Token.

## setEnvironment

This function sets environment name.

Name of Environment

## getEnvironment

This function returns environment name.

## setBranch

This function sets Branch.

Name of branch

## Branch

This function returns Branch.

## getContentTypes

This call returns comprehensive information of all the content types available in a particular stack in your account.

Query params for getting content-type.

## sync

Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates

initializing sync

initializing sync with entries of a specific locale

initializing sync with entries of a specific content type

Use the type parameter to get a specific type of content.Supports 'asset\_published', 'entry\_published', 'asset\_unpublished', 'entry\_unpublished', 'asset\_deleted', 'entry\_deleted', 'content\_type\_deleted'

Fetching the next batch of entries using pagination token

Performing subsequent sync after initial sync

## Result

Response as result

## get

Get the keys value from the object

## toJSON

To convert result object to json

## Assets

Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use.

## Query

Query object to create the "Query" on Assets

## fetch

Fetch the specified assets

Uid for asset to be fetch

## ContentType

ContentType provides Entry and Query instance.

## fetch

Fetch the specific content type

Parameters to fetch content

## Entry

Entry object to create the "Query" on the specified ContentType

Entry uid to get details

## Query

A query that is used to query for Entry instance.

## Entry

An initializer is responsible for creating Entry object.

## language

To set the language code for entry to fetch

Language code by default is "en-us"

## includeContentType

To include content\_type along with entries.

## includeReferenceContentTypeUID

This method includes the content type UIDs of the referenced entries returned in the response.

## includeReference

To include reference(s) of other content type in entries

Array of reference field uids.

## includeEmbeddedItems

To include Embedded Items along with entries and asset.

## includeBranch

To include branch of publish content.

## only

To project the fields in the result set

Level for which field uid to include. Set 'BASE' for top level.

field uids as array

## except

To exclude the fields from the result set.

Level for which field uid to except. Set 'BASE' for top level.

field uids as array

## toJSON

To transform the Result object to server response content

## fetch

Fetch the specified entry

Uid for the entry instance.

ContentType uid for the entry instance.

## Query

An initializer is responsible for creating Query object.

## getQuery

Get the raw/array query from the current instance of Query/Entry.

## addQuery

Add Query is used to add the raw/array query to filter the entries.

Array formatted query

## addParam

To add query parameter in query

Name of key in string

Value of the key in string

## includeReferenceContentTypeUID

This method includes the content type UIDs of the referenced entries returned in the response.

## includeContentType

To include content\_type along with entries.

## includeCount

Retrieve count and data of objects in result.

## includeBranch

Include branch for publish content.

## includeFallback

Include fallback locale publish content, if specified locale content is not publish.

## includeEmbeddedItems

Include Embedded Objects (Entries and Assets) along with entry/entries details.

## includeReference

Add a constraint that requires a particular reference key details.

Array of reference field uids

## regex

Add a regular expression constraint for finding string values that match the provided regular expression.

The key to be constrained.

The regular expression pattern to match.

Any of the following supported Regular expression modifiers.

*   use _i_ for case-insensitive matching.
*   use _m_ for making dot match newlines.
*   use _x_ for ignoring whitespace in regex

## language

To set the language code in the query

Language code to get entries form stack

## tags

Include tags with which to search entries.

Array of tags you want to match in the entries

## limit

A limit on the number of objects to return.

No of objects to limit.

## skip

The number of objects to skip before returning any.

No of objects to skip.

## ascending

Sort the results in ascending order with the given key.

The key to order by.

## descending

Sort the results in descending order with the given key.

The key to order by.

## logicalOR

Combines all the queries together using OR operator

Array of Query instances on which OR query executes.

## logicalAND

Combines all the queries together using AND operator

Array of Query instances on which AND query executes.

## except

Specifies list of field uids that would be excluded from the response.

Level for field uid

Field uid which get excluded from the response.

## exists

Add a constraint that requires, a specified key does exists in response.

Field uid against the value not existence is checked

## notExists

Add a constraint that requires, a specified key does not exists in response.

Field uid against the value not existence is checked

## where

Query the field which has exact value as specified

Field in the entry against which comparison needs to be done.

Value against which comparision is going to happen

## notEqualTo

Query the field which has not equal to value than specified one

Field in the entry against which comparison needs to be done.

Value against which comparision is going to happen

## containedIn

Query the field value from the given set of values

Field in the entry against which comparison needs to be done.

Array value against which comparison is going to happen

## notContainedIn

Query the field value other than the given set of values

Field in the entry against which comparison needs to be done.

Array value against which comparison is going to happen

## lessThan

Query the field which has less value than specified one

Field in the entry against which comparison needs to be done.

Value against which comparison is going to happen

## lessThanEqualTo

Query the field which has less or equal value than specified one

Field in the entry against which comparison needs to be done.

Value against which comparison is going to happen

## greaterThan

Query the field which has greater value than specified one

Field in the entry against which comparison needs to be done.

Value against which comparison is going to happen

## greaterThanEqualTo

Query the field which has greater or equal value than specified one.

Field in the entry against which comparision needs to be done

Value against which comparision is going to happen

## find

Get all entries based on the specified subquery

## count

To get only count result