Get Started with PHP SDK

This guide will help you get started with Contentstack PHP SDK to build apps powered by Contentstack.


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

  • PHP version 5.5.0 or later

SDK Installation and Setup

To use the PHP SDK, you need to perform the following steps:

  1. Download/clone the PHP SDK.
  2. Paste the downloaded ZIP file of the PHP SDK to a folder of your choice.

Let's get started with the implementation.

Initialize SDK

To initialize the SDK, specify the stack’s API keydelivery token, and name of the environment where you will publish the content.

use Contentstack\Contentstack;
include_once "contentstack/index.php";
$stack = Contentstack::Stack(API_KEY, DELIVERY_TOKEN, ENV_NAME);

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

Basic Queries

Contentstack SDKs let you interact with the Content Delivery APIs 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, you need to specify the content type and the UID of the entry:

$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:

$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. For advanced queries, refer to the Contentstack PHP SDK API reference.

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 section of our Content Delivery API documentation.

Paginating Responses

In a single instance, the 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 skip and limit parameters in subsequent requests.

$stack = Contentstack::Stack(API_KEY, DELIVERY_TOKEN, ENV_NAME);
$result = $stack->ContentType(CONTENT_TYPE_UID)->Query()->toJSON()->skip(20)->limit(20)->find()


  • We have a URL size limitation of 8KB on API Requests that hit our CDN services. Any Request URL that goes above this size limit will receive the 400 - Bad request error response. Please make sure you limit the size of your API Requests.
  • The PHP SDK does not support multiple content types referencing in a single query.
  • Currently, the PHP SDK does not support retrieving details of Global Fields.

More Resources

Was this article helpful?

Thanks for your feedbackSmile-icon

More articles in "Use PHP SDK"

On This Page