cs-icon.svg

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.

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, 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 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 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, delivery token, and environment 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), or Azure Europe (Azure_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 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:

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

Returns:
Type
Stack
NameTypeDescription

api_key (required)

string

API Key of your stack on Contentstack.

access_token (required)

string

Delivery token of your stack on Contentstack.

environment (required)

string

Environment from where you want to fetch content.

config

array

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');

ContentstackRegion

Fields

NameDescription
EU

To specify the EU region.

US

To specify the US region.

AZURE_NA

To specify the AZURE NA region

AZURE_EUTo specify the AZURE_EU region

CSException

CSException CSException Class is used to wrap the REST API error

NameTypeDescription

error_message

string

Contentstack error message.

error_code

string

Contentstack Error code

http_code

int

API http status code

getErrors

Returns error details of current exception



Returns:
Type
error|array

getStatusCode

To get http status_code of the current exception



Returns:
Type
HttpCode|string

Stack

Stack Class to initialize the provided parameter Stack

ContentType

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

Returns:
Type
ContentType
NameTypeDescription

content_type_uid (required)

string

Valid content type uid relevant to configured stack

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$content_type = $stack->ContentType('content_type_uid');
Returns:
Type
ContentType
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$content_types = $stack->ContentType();

Assets

Assets Class to initalize your Assets

Returns:
Type
Assets
NameTypeDescription

asset_uid (required)

string

valid asset uid relevent to configured stack

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$assets = $stack->Assets('asset_uid');
Returns:
Type
Assets
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$assets = $stack->Assets();

ImageTrasform

ImageTrasform function is define for image manipulation with different

Returns:
Type
string
NameTypeDescription

url (required)

string

Image url on which we want to manipulate.

parameters (required)

object

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

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result_url = $stack->ImageTrasform('url', array('quality' => 100));

LivePreviewQuery

To set live preview token and content type uid.

Returns:
Type
void
NameTypeDescription

parameters (required)

object

Set live preview token and content type uid.

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->LivePreviewQuery(array('live_preview'=> 'token', 'content_type_uid'=? 'content_type_uid', 'entry_uid'=> 'entry_uid'));

getLastActivities

To get the last_activity information of the configured environment from all the content types.

Returns:
Type
object
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->getLastActivities();

setHost

To set the host on stack object

Returns:
Type
Stack
NameTypeDescription

host (required)

string

Host name/ipaddress from where the content to be fetched

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setHost('host');

getHost

This function returns host.

Returns:
Type
string
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$host = $stack->getHost();

setProtocol

This function sets protocol.

Returns:
Type
Stack
NameTypeDescription

protocol (required)

string

Protocol type

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setProtocol('protocol');

getProtocol

This function return protocol type.

Returns:
Type
string
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$protocol = $stack->getProtocol();

setPort

This function sets Port.

Returns:
Type
Stack
NameTypeDescription

port (required)

string

Port Number

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setPort('port');

getPort

This function return Port.

Returns:
Type
string
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$port = $stack->getPort();

setAPIKEY

This function sets API Key.

Returns:
Type
void
NameTypeDescription

api_key (required)

string

Stack API key

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setAPIKEY('api_key');

getAPIKEY

This function returns API Key.

Returns:
Type
string
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$api_key = $stack->getAPIKEY();

setDeliveryToken

This function sets Delivery Token.

Returns:
Type
Stack
NameTypeDescription

delivery_token (required)

string

Environment specific delivery token

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setDeliveryToken('delivery_token');

DeliveryToken

This function returns Delivery Token.

Returns:
Type
string
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$token = $stack->DeliveryToken();

setEnvironment

This function sets environment name.

Returns:
Type
Stack
NameTypeDescription

environment (required)

string

Name of Environment

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setEnvironment('environment');

getEnvironment

This function returns environment name.

Returns:
Type
string
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$environment = $stack->getEnvironment();

setBranch

This function sets Branch.

Returns:
Type
Stack
NameTypeDescription

branch (required)

string

Name of branch

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$stack->setBranch('branch');

Branch

This function returns Branch.
Returns:
Type
string
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$branch = $stack->Branch();

getContentTypes

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



Returns:
Type
object
NameTypeDescription

params

object

Query params for getting content-type.

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->getContentTypes();

sync

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

param.init

boolean

initializing sync

param.locale

string

initializing sync with entries of a specific locale

param.start_date

string

Default: initializing sync with entries published after a specific date

param.content_type_uid

string

initializing sync with entries of a specific content type

param.type

string

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'

param.pagination_token

string

Fetching the next batch of entries using pagination token

param.sync_token

string

Performing subsequent sync after initial sync

For initializing sync:

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true});

For initializing sync with entries of a specific locale:

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true, 'locale'=> 'en-us'});

For initializing sync with entries published after a specific date:

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true, 'start_date'=> '2018-10-22'});

For initializing sync with entries of a specific content type:

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true, 'content_type_uid'=> 'session'});

For initializing sync with specific type:

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true, 'type'=> 'entry_published'});

For fetching the next batch of entries using pagination token:

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'pagination_token'=> '<page_token>'});

For performing subsequent sync after initial sync:

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'sync_token'=> '<sync_token>'}) 

Result

Response as result

get

Get the keys value from the object

Returns:
Type
Value
NameTypeDescription

key (required)

string

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true});
$json = $result->get('key');

toJSON

To convert result object to json

Returns:
Type
json
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->sync({'init'=> true});
$json = $result->toJSON();

Assets

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

NameTypeDescription

assetUid

string

Uid for asset to be fetch

Query

Query object to create the "Query" on Assets

Returns:
Type
Query
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->Assets()->Query()->find;

fetch

Fetch the specified assets

Returns:
Type
Result
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->Assets('asset_uid')->fetch();

ContentType

ContentType provides Entry and Query instance.

fetch

Fetch the specific content type

Returns:
Type
Result
NameTypeDescription

params

object

Parameters to fetch content

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack-ContentType('content_type_uid')->fetch();

Entry

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

Returns:
Type
Query
NameTypeDescription

uid (required)

string

Entry uid to get details

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$entry = $stack-ContentType('content_type_uid')->Entry('entry_uid');

Query

A query that is used to query for Entry instance.

Returns:
Type
Query
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$query = $stack-ContentType('content_type_uid')->Query();

Entry

An initializer is responsible for creating Entry object.

NameTypeDescription

entryUid

string

Uid for the entry instance.

contentType

string

ContentType uid for the entry instance.

language

To set the language code for entry to fetch

Returns:
Type
Entry
NameTypeDescription

locale (required)

string

Language code by default is "en-us"

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->language('en-us')->fetch();

includeContentType

To include content_type along with entries.

Returns:
Type
Entry
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->includeContentType()->fetch();

includeReferenceContentTypeUID

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

Returns:
Type
Entry
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->includeReferenceContentTypeUID()->fetch();

includeReference

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

Returns:
Type
Entry
NameTypeDescription

field_uids (required)

array

Array of reference field uids.

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->includeReference(array('categories')))->fetch();

includeEmbeddedItems

To include Embedded Items along with entries and asset.

Returns:
Type
Entry
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->includeEmbeddedItems()->fetch();

includeBranch

To include branch of publish content.

Returns:
Type
Entry
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->includeBranch()->fetch();

only

To project the fields in the result set

Returns:
Type
Entry
NameTypeDescription

level (required)

string

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

field_uids (required)

string

field uids as array

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->toJSON()->only('BASE',array('price'))->fetch();

except

To exclude the fields from the result set.

Returns:
Type
Entry
NameTypeDescription

level (required)

string

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

field_uids (required)

string

field uids as array

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->toJSON()->except('BASE',array('price'))->fetch();

toJSON

To transform the Result object to server response content

Returns:
Type
JSON
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')-toJSON()->fetch();

fetch

Fetch the specified entry

Returns:
Type
Result
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Entry('entry_uid')->fetch();

Query

An initializer is responsible for creating Query object.

getQuery

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

Returns:
Type
RawQuery
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$_set = ['vivo', 'samsung', 'redmi 3', 'apple'];
$result = $stack->ContentType('content_type_uid')->Query()->containsIn('title', $_set)->getQuery();

addQuery

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

Returns:
Type
Query
NameTypeDescription

query (required)

array

Array formatted query

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$_set = ['vivo', 'samsung', 'redmi 3', 'apple'];
$query1 = $stack->ContentType('content_type_uid_1')->Query()->containsIn('title', $_set)->getQuery();
$result = $stack->ContentType('content_type_uid')->Query()->addQuery($query1)->find();

addParam

To add query parameter in query

Returns:
Type
Query
NameTypeDescription

key (required)

string

Name of key in string

value (required)

string

Value of the key in string

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->addParam('include_count', 'true')->find();

includeReferenceContentTypeUID

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

Returns:
Type
Query
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeReferenceContentTypeUID()->find();

includeContentType

To include content_type along with entries.

Returns:
Type
Query
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeContentType()->find();

includeCount

Retrieve count and data of objects in result.

Returns:
Type
Query
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeCount()->find();

includeBranch

Include branch for publish content.

Returns:
Type
Query
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeBranch()->find();

includeFallback

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

Returns:
Type
Query
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeFallback()->find();

includeEmbeddedItems

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

Returns:
Type
Query
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeEmbeddedItems()->find();

includeReference

Add a constraint that requires a particular reference key details.

Returns:
Type
Query
NameTypeDescription

field_uids (required)

array

Array of reference field uids

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->includeReference(array('reference_uid_1', 'reference_uid_2'))->find();

regex

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

Returns:
Type
Query
NameTypeDescription

key (required)

string

The key to be constrained.

regex (required)

string

The regular expression pattern to match.

modifiers

string

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
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->regex('name', '^browser')->find();

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->regex('name', '^browser', 'i')->find();

language

To set the language code in the query

Returns:
Type
Query
NameTypeDescription

lang (required)

string

Language code to get entries form stack

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->language('en-us')->find();

tags

Include tags with which to search entries.

Returns:
Type
Query
NameTypeDescription

tags (required)

array

Array of tags you want to match in the entries

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->tags(array('tag1', 'tag2'))->find();

limit

A limit on the number of objects to return.

Returns:
Type
Query
NameTypeDescription

limit (required)

int

No of objects to limit.

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->limit(20)->find();

skip

The number of objects to skip before returning any.

Returns:
Type
Query
NameTypeDescription

skip (required)

int

No of objects to skip.

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->skip(20)->find();

ascending

Sort the results in ascending order with the given key.

Returns:
Type
Query
NameTypeDescription

field_uid (required)

string

The key to order by.

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->ascending('name')->find();

descending

Sort the results in descending order with the given key.

Returns:
Type
Query
NameTypeDescription

field_uid (required)

string

The key to order by.

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->descending('name')->find();

logicalOR

Combines all the queries together using OR operator

Returns:
Type
Query
NameTypeDescription

queries (required)

array

Array of Query instances on which OR query executes.

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$query1 = $stack->ContentType('content_type_uid_1')->Query()->where('title', 'Redmi Note 3');
$query2 = $stack->ContentType('content_type_uid_1')->Query()->where('color', 'Gold');
$result = $stack->ContentType('content_type_uid')->Query()->logicalOr(array($query1, $query2))->find();

logicalAND

Combines all the queries together using AND operator

Returns:
Type
Query
NameTypeDescription

queries (required)

array

Array of Query instances on which AND query executes.

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$query1 = $stack->ContentType('content_type_uid_1')->Query()->where('title', 'Redmi Note 3');
$query2 = $stack->ContentType('
')->Query()->where('color', 'Gold');
$result = $stack->ContentType('content_type_uid')->Query()->logicalAND(array($query1, $query2))->find();

except

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

Returns:
Type
Query
NameTypeDescription

level (required)

string

Level for field uid

field_uid (required)

array

Field uid which get excluded from the response.

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->except('BASE',array('price'))->find();

exists

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

Returns:
Type
Query
NameTypeDescription

field_uid (required)

string

Field uid against the value not existence is checked

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->exists('age')->find();

notExists

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

Returns:
Type
Query
NameTypeDescription

field_uid (required)

string

Field uid against the value not existence is checked

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->notExists('age')->find();

where

Query the field which has exact value as specified

Returns:
Type
Query
NameTypeDescription

field (required)

string

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

value (required)

string

Value against which comparision is going to happen

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->where('age', '20')->find();

notEqualTo

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





Returns:
Type
Query
NameTypeDescription

field (required)

string

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

value (required)

string

Value against which comparision is going to happen

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->notEqualTo('age', '20')->find();

containedIn

Query the field value from the given set of values





Returns:
Type
Query
NameTypeDescription

field (required)

string

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

value (required)

string

Array value against which comparison is going to happen

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->containedIn("field_uid", ["Christmas Deal", "Summer Deal"])->find();

notContainedIn

Query the field value other than the given set of values





Returns:
Type
Query
NameTypeDescription

field (required)

string

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

value (required)

string

Array value against which comparison is going to happen

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->notContainedIn("field_uid", ["Christmas Deal", "Summer Deal"])->find();

lessThan

Query the field which has less value than specified one





Returns:
Type
Query
NameTypeDescription

field (required)

string

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

value (required)

string

Value against which comparison is going to happen

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->lessThan('age', 20)->find();

lessThanEqualTo

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





Returns:
Type
Query
NameTypeDescription

field (required)

string

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

value (required)

string

Value against which comparison is going to happen

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->lessThanEqualTo('age', 20)->find();

greaterThan

Query the field which has greater value than specified one



Returns:
Type
Query
NameTypeDescription

field

string

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

value (required)

string

Value against which comparison is going to happen

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->greaterThan('age', 20)->find();

greaterThanEqualTo

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

Returns:
Type
Query
NameTypeDescription

field (required)

string

Field in the entry against which comparision needs to be done

value (required)

string

Value against which comparision is going to happen

use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->greaterThanEqualTo('age', 20)->find();

find

Get all entries based on the specified subquery

Returns:
Type
Result
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->find();

count

To get only count result

Returns:
Type
Query
use Contentstack\Contentstack;
$stack = Contentstack::Stack('api_key', 'delivery_token', 'environment');
$result = $stack->ContentType('content_type_uid')->Query()->count()->find();