PHPackages                             incraigulous/contentful-sdk - 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. incraigulous/contentful-sdk

ActiveLibrary[API Development](/categories/api)

incraigulous/contentful-sdk
===========================

1.0(10y ago)1415.0k10[2 PRs](https://github.com/incraigulous/contentful-sdk/pulls)1MITPHPPHP &gt;=5.4.0

Since Mar 27Pushed 3y ago3 watchersCompare

[ Source](https://github.com/incraigulous/contentful-sdk)[ Packagist](https://packagist.org/packages/incraigulous/contentful-sdk)[ RSS](/packages/incraigulous-contentful-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (2)Versions (7)Used By (1)

[![Latest Stable Version](https://camo.githubusercontent.com/d13688a1203a4db691c60738bf0701bc28d72a63f1a786d21b23a7c2cbdf10c5/68747470733a2f2f706f7365722e707567782e6f72672f696e6372616967756c6f75732f636f6e74656e7466756c2d73646b2f762f737461626c652e737667)](https://packagist.org/packages/incraigulous/contentful-sdk) [![Total Downloads](https://camo.githubusercontent.com/08ed9582b26ef54adf860eb6fce72d7290262cc64b3d44ffb156b89380dce479/68747470733a2f2f706f7365722e707567782e6f72672f696e6372616967756c6f75732f636f6e74656e7466756c2d73646b2f646f776e6c6f6164732e737667)](https://packagist.org/packages/incraigulous/contentful-sdk) [![Latest Unstable Version](https://camo.githubusercontent.com/55b2533980558e12fe6a6e624275cdfac13d20901d6f403659e90f975f170448/68747470733a2f2f706f7365722e707567782e6f72672f696e6372616967756c6f75732f636f6e74656e7466756c2d73646b2f762f756e737461626c652e737667)](https://packagist.org/packages/incraigulous/contentful-sdk) [![License](https://camo.githubusercontent.com/3864c0d39439273179ec036bb3fce33aeb169cd758eaa224a261c8490cc1c374/68747470733a2f2f706f7365722e707567782e6f72672f6c656170686c792f636172742d62756e646c652f6c6963656e73652e737667)](https://packagist.org/packages/leaphly/cart-bundle) [![Daily Downloads](https://camo.githubusercontent.com/f9982769395a5203a2928cefcaf69d36da23010f49dddfaf9ac34d5a9d2f468a/68747470733a2f2f706f7365722e707567782e6f72672f696e6372616967756c6f75732f636f6e74656e7466756c2d73646b2f642f6461696c792e706e67)](https://packagist.org/packages/incraigulous/contentful-sdk) [![Build Status](https://camo.githubusercontent.com/a8df54196475a4fcfbbb22bbbe2da1c53eb58cec19f22f063cf9116e1b20e3a9/68747470733a2f2f7472617669732d63692e6f72672f696e6372616967756c6f75732f636f6e74656e7466756c2d73646b2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/incraigulous/contentful-sdk)

\#DEPRECATED. Use Contentful's official PHP SDK.

Contentful SDK for PHP
----------------------

[](#contentful-sdk-for-php)

A modern PHP SDK for Contentful delivery and management APIs.

\###This is a framework agnostic PHP SDK.

\####Looking for the Laravel Toolkit?

[Click Here](https://github.com/incraigulous/contentful-laravel) for Laravel facades, a base repository, out-of-the-box caching and cache management, webhook creation by command and more.

> ***New to Contentful?*** Contentful is an API driven CMS. Check out their [website](https://www.contentful.com/) and [API documentation](https://www.contentful.com/developers/documentation/content-delivery-api/).

\##Installation

Install via composer by running:

```
composer require "incraigulous/contentful-sdk:0.0.*"

```

\##How to use it

\###Content Delivery API

\####Initializing

Create a new instance of the delivery SDK:

```
    use Incraigulous\ContentfulSDK\DeliverySDK;
    $deliverySDK = new DeliverySDK('TOKEN', 'SPACE_ID', $cacher);

```

**Token:** Your Contentful API token. You can generate this using the Contentful control panel.

**Space ID:** *(optional)* The space to use for calls made by the instance. To use multiple spaces, you should use multiple SDK instances. If you don't provide a space ID, you'll only be able to use the `spaces` resource.

**Cacher:** *(optional, Incraigulous\\ContentfulSDK\\CacherInterface Implementation)* An object to handle caching. This is optional (and easy to implement), so don't let it scare you off. Check out the [caching](https://github.com/incraigulous/contentful-sdk/blob/master/readme.md#caching) section for more details.

\####Spaces

\#####Getting all spaces

```
$result = $deliverySDK->spaces()->get();

```

\#####Getting a space

```
$result = $deliverySDK->spaces()
				->find('SPACE_ID')
				->get();

```

\####Content Types

\#####Getting a content type

```
$result = $deliverySDK->contentTypes()
				->find('CONTENT_TYPE_ID')
				->get();

```

\#####Searching content types

```
$result = $deliverySDK->contentTypes()
				->where('name', '=', 'Blog Post')
				->get();

```

or

```
$result = $deliverySDK->contentTypes()
				->where('name', 'ne', 'Blog Post')
				->limit(2)
				->get();

```

See [Search Parameters](https://github.com/incraigulous/contentful-sdk#search-parameters) to learn how to search for specific things.

\####Entries

\#####Get an Entry by ID

```
$result = $deliverySDK->entries()
				->find('ENTRY ID')
				->get();

```

\#####Searching for entries

```
$result = $deliverySDK->entries()
				->limitByType('CONTENT TYPE ID')
				->where('fields.title', 'match', 'campus')
				->where('fields.location', 'near', '22,23')
				->limit(10)
				->get();

```

\######Including linked entries in search results

```
$result = $deliverySDK
	->where('sys.id', '=', 'ENTRY ID')
	->includeLinks(3)
	->get();

```

`includeLinks` takes the number of link levels you want to include.

\####Assets

\#####List all assets

```
$result = $deliverySDK->assets()
            	->limit(10)
            	->get();

```

\#####Get an asset by ID

```
$deliverySDK->assets()
            	->find('ASSET ID')
            	->get();

```

\#####Searching for assets

```
$result = $deliverySDK->assets()
              ->where('fields.file.details.size', '>=', 350000)
              ->limit(5)
              ->get();

```

\####Search Parameters

Searching is easy! Just call one or more of the following methods on your resource. The use of where() and limit() on the assets resource as shown above is a great example of searching.

MethodParametersDescriptionfindidLimit results by IDwherefield, operator, valueLimit results by operator searchfullsearchAlias for `query`querysearchSearch all records for text match. See filters below.orderorderBy, $reverse = falseOrder results by a fieldlimitnumberLimit results by a quantityskipnumberSkip a quantity of results\#####Where Filter Operators

Accepted ValuesProduces Contentful OperatorDescription==**Equality:** Search for exact matches!=, \[ne\], ne\[ne\]**Inequality:** Search for exact matches\[in\], in\[in\]**Inclusion:** Search for multiple matches\[nin\], nin\[nin\]**Exclusion:** Search for multiple matches&lt;, \[lt\], lt\[lt\]**Less Than:** Number &amp; date ranges&gt;, \[gt\], gt\[gt\]**Greater Than:** Number &amp; date ranges&gt;=, \[gte\], gte\[gte\]**Greater Than or Equal To:** Number &amp; date rangesmatch, \[match\]\[match\]**Match:** Full-text search on a specific fieldnear, \[near\]\[near\]**Near:** Search for location near positionwithin, \[within\]\[within\]**Within:** Search for location within bounding rectangle*Anything not listed*\['YOUR OPERATOR HERE'\]**Default**> For more detailed documentation on searching, see [Contentful's API documentation](https://www.contentful.com/developers/documentation/content-delivery-api/).

\#####Caching

I recommend you cache all Delivery API GET request results (i.e. Memcached or Redis). If you're working with a low traffic website you might be able to get by without caching, but it will greatly improve performance in any case.

One way would be to wrap all your API GET calls in a cache check, but that could lead to code duplication. Lucky for you, there's a better way.

I've included a cacher interface. Don't worry, it only requires four methods. Just build a class that implements `Incraigulous\ContentfulSDK\CacherInterface` and pass it as the third parameter when you instantiate the SDK. The SDK will handle the rest. Each GET request will be cached with a unique key built from the query using your cacher class.

```
	$cacher = new CustomCacher();
    $deliverySDK = new DeliverySDK('SPACE_ID', 'TOKEN', $cacher);

```

[Here's an example](https://github.com/incraigulous/contentful-laravel/blob/master/src/Incraigulous/Contentful/Cacher.php) using Laravel's Cache helper.

\######If you build a generic PHP cacher implementation for Redis or Memcached, submit a pull request. I would love to include it in the repo.

\###Management API

\####Initializing

Create a new instance of the management SDK:

```
    use Incraigulous\ContentfulSDK\ManagementSDK;
    $managementSDK = new ManagementSDK('TOKEN', 'SPACE_ID');

```

**Token:** Your Contentful OAuth token.

**Space ID:** *(optional)* The space to use for calls made by the instance. To use multiple spaces, you should use multiple SDK instances. If you don't provide a space ID, you'll only be able to use the `spaces` resource.

> Note that there is a third parameter for the cacher. Management API calls are not currently cached to make sure that `GET` requests are up to date to avoid conflicts when updating records. I still wanted to allow a place to provide the cacher just in case I decide to use it for anything. Feel free to ignore it, or provide a cacher for good measure.

\####Using Builder Objects Contentful payloads can be complex, especially when working with `entries` or `assets`. Payload builders are here to help! They're optional helper classes to assist with building payloads. They take care of building payload arrays for you and let you know what options you have along the way. They're especially helpful if your IDE has hinting.

If you don't want to use them, don't use them. The SDK parases the payload looking for builder objects and turns them into arrays before passing requests on to Contentful. As such, you are free to use standard arrays, or arrays made up of payload builder objects.

The following examples will assume you're using the builders you need:

```
use Incraigulous\ContentfulSDK\PayloadBuilders\Entry;
use Incraigulous\ContentfulSDK\PayloadBuilders\EntryField;
use Incraigulous\ContentfulSDK\PayloadBuilders\Space;
...

```

\####Spaces

\#####Creating a space

```
$result = $managementSDK->spaces()
				->post(
					new Space('My Space')
				);

```

\#####Updating a space

```
$space = $managementSDK->spaces()
             ->find('SPACE_ID')
             ->get();

$space['name'] = 'Outer Space';
$result = $managementSDK->spaces()->put('SPACE_ID', $space);

```

\#####Deleting a space

```
$result = $managementSDK->spaces()->delete('SPACE_ID');

```

\####Content Types

\#####Creating a content type

```
$result = $managementSDK->contentTypes()
                ->post(
                    new ContentType('Blog Post', 'title', [
                        new ContentTypeField('title', 'Title', 'Text'),
                        new ContentTypeField('body', 'Body', 'Text'),
                    ])
                );
            );

```

\#####Creating a content type with validation and links

```
$result = $managementSDK->contentTypes()
                ->post(
                    new ContentType('Blog Post', 'title', [
                        new ContentTypeField('title', 'Title', 'Text'),
                        new ContentTypeField('body', 'Body', 'Text'),
                        (new ContentTypeField('author', 'Field List', 'Link'))->setLink('Entry'),
                        (new ContentTypeField('sidebar', 'Field List', 'Array'))->setMultiLink('Entry'),
                        (new ContentTypeField('category', 'Category', 'Text'))->setValidations((new ContentTypeValidation())->in(['Design', 'Development'])),
                    ])
                );

```

\#####Updating a content type

```
$contentType = $managementSDK->contentTypes()
					->find('CONTENT_TYPE_ID')
					->get();

$contentType['fields'][0]['name'] = 'Post Title';
$result = $managementSDK->contentTypes()->put('CONTENT_TYPE_ID', $contentType);

```

\#####Publishing a content type

```
$contentType = $managementSDK->contentTypes()
					->find('CONTENT_TYPE_ID')
					->get();

$result = $managementSDK->contentTypes()->publish('CONTENT_TYPE_ID', $contentType);

```

\#####Unublishing a content type

```
$contentType = $managementSDK->contentTypes()
					->find('CONTENT_TYPE_ID')
					->get();

$result = $managementSDK->contentTypes()->unpublish('CONTENT_TYPE_ID', $contentType);

```

\#####Deleting a content type

```
$result = $managementSDK->contentTypes()->delete('CONTENT_TYPE_ID');

```

\#####Content Type Payload Builder

ParametersDescriptionnameThe content type namedisplayFieldthe title field keycontentTypeFieldsan array of content type fields. Can be a pure array or an array of ContentTypeField builder objects.\#####Content Type Field Payload Builder

ParametersDescriptionidThe content type field idnameThe content type field nametypeThe content type field typerequired(default: false) is the field requiredlocalized(default: false) is the field localizedMethodsParametersDescriptionsetLinklinkType (default: Entry)Add a link to the fieldsetMultiLinklinkType (default: Entry)Add multiple links to the fieldsetValidationsvalidationsA validations array or a contentTypeValidations payload builder object\#####Content Type Field Validations Payload Builder

Takes no parameters.

MethodsParametersDescriptionsizemin (default: null), max (default: null)Validates that the size of a text, object or array is within a range.inset (array)Validates that the value of a field belongs to a predefined set. It's defined specifying the elements that form the valid set.regexp$pattern, $flags (default: null)Validates that the value of a field matches a Regular Expression.dateRangemin (default: null), max (default: null)Validates that the value of a field is within a date range.assetFileSizemin (default: null), max (default: null)Validates that the size of an asset is within a range.assetImageDimensionsheight (default: null), width (default: null)Validates that the dimensions of an image are within a range.\####Entries

\#####Creating an entry

```
$result = $managementSDK->entries()->contentType('CONTENT_TYPE_ID')->post(
            new Entry([
                    new EntryField('title', 'Hello, World!'), //Create a field with only the default language
                    (new EntryField('body'))->addLanguage('en-US', 'Bacon is healthy!') //Add a language to a field.
                ])
        );

```

Note that you are able to add content to a field without specifying a language. The default default language is `en-US`. To specify a different default language, define a `CONTENTFUL_DEFAULT_LANGUAGE` constant.

Example:

```
define('CONTENTFUL_DEFAULT_LANGUAGE', 'de-DE');

```

\#####Creating an entry while specifying an ID

```
$result = $managementSDK->entries()->put('MY_CUSTOM_ID',
		new Entry([
                    new EntryField('title', 'Hello, World!'),
                    (new EntryField('body'))->addLanguage('en-US', 'Bacon is healthy!')
                ])
        );

```

\#####Creating an entry with a linked field

```
$result = $managementSDK->entries()->contentType('CONTENT_TYPE_ID')->post(new Entry([
            new EntryField('title', 'Hello, World!'),
           (new EntryField('body'))->addLanguage('en-US', 'Bacon is healthy!'),
           (new EntryField('sidebar'))->addMultiLink('ENTRY_ID', 'Entry')->addMultiLink('ENTRY_ID', 'Entry'),
           (new EntryField('author'))->addLink('ENTRY_ID', 'Entry')
        ]));

```

\#####Updating an entry

```
$entry = $managementSDK->entries()
					->find('ENTRY_ID')
					->get();

$entry['fields']['title'] = new EntryField('title', 'Cheese is Healthy!');
$result = $managementSDK->entries()->put('ENTRY_ID', $entry);

```

\#####Publishing an entry

```
$entry = $managementSDK->entries()->find('ENTRY_ID')->get();
$result = $managementSDK->entries()->publish('ENTRY_ID', $entry);

```

\#####Unpublishing an entry

```
$entry = $managementSDK->entries()->find('ENTRY_ID')->get();
$result = $managementSDK->entries()->unpublish('ENTRY_ID', $entry);

```

\#####Archiving an entry

```
$result = $managementSDK->entries()->archive('ENTRY_ID');

```

\#####Unarchiving an entry

```
$result = $managementSDK->entries()->unarchive('ENTRY_ID');

```

\#####Deleting an entry

```
$result = $managementSDK->entries()->delete('ENTRY_ID');

```

\#####Entry Payload Builder

ParametersDescriptionfieldsAn array of entry fields. Can be a pure array or an array of EntryField builder objects.\#####Entry Field Payload Builder

ParametersDescriptionnameThe field namecontentThe field contentlanguage(default: en-US or CONTENTFUL\_DEFAULT\_LANGUAGE constant) The default field language.MethodsParametersDescriptionaddLanguagelanguageKeyAdd a language to the field.addLinkid, linkType (default: Entry), languageKey (default: en-US or CONTENTFUL\_DEFAULT\_LANGUAGE constant)Create a relationship to a resource.addMultiLinkid, linkType (default: Entry), languageKey (default: en-US or CONTENTFUL\_DEFAULT\_LANGUAGE constant)Create relationships to resources.\####Assets

\#####Creating an asset

```
$result = $managementSDK->assets()->post(new Asset([
                    new AssetField('title', 'Bacon Pancakes'),
                    new File("image/jpeg", "example.jpg", "https://example.com/example.jpg")
                ])
        );

```

\#####Creating an asset while specifying an ID

```
$result = $managementSDK->assets()->put('MY_CUSTOM_ID', new Asset([
                    new AssetField('title', 'Bacon Pancakes'),
                    new File("image/jpeg", "example.jpg", "https://example.com/example.jpg")
                ])
        );

```

\#####Updating an asset

```
$asset = $managementSDK->assets()->find('ASSET_ID')->get();

$asset['fields']['file'] = new File("image/jpeg", "example.jpg", "https://example.com/example.jpg");
$result = $managementSDK->assets()->put('ASSET_ID', $asset);

```

\#####Processing an asset

```
$result = $managementSDK->assets()->process('ASSET_ID');

```

\#####Publishing an asset

```
$asset = $managementSDK->assets()->find('ASSET_ID')->get();
$result = $managementSDK->assets()->publish('ASSET_ID', $asset);

```

\#####Unpublishing an asset

```
$asset = $managementSDK->assets()->find('ASSET_ID')->get();
$result = $managementSDK->assets()->unpublish('ASSET_ID', $asset);

```

\#####Archiving an asset

```
$result = $managementSDK->assets()->archive('ASSET_ID');

```

\#####Unarchiving an asset

```
$result = $managementSDK->assets()->unarchive('ASSET_ID');

```

\#####Deleting an asset

```
$result = $managementSDK->assets()->delete('ASSET_ID');

```

\#####Asset Payload Builder

ParametersDescriptionfieldsAn array of asset fields. Can be a pure array or an array of AssetField builder objects.\#####Asset Field Payload Builder

ParametersDescriptionnameThe field namecontentThe field contentlanguage(default: en-US or CONTENTFUL\_DEFAULT\_LANGUAGE constant) The default field languageMethodsParametersDescriptionaddLanguagelanguageKeyAdd a language to the field.\#####File Payload Builder

ParametersDescriptioncontentTypeThe file content typefileNameThe file nameuploadThe upload pathlanguage(default: en-US or CONTENTFUL\_DEFAULT\_LANGUAGE constant) The language\####Webhooks

\#####Creating a webhook

```
$result = $managementSDK->webhooks()->post(
			new Webhook('http://www.example.com/')
		);

```

\#####Updating a webhook, or creating new a webhook with a set ID

```
$result = $managementSDK->webhooks()->put('WEBHOOK_ID',
			new Webhook('http://www.example.com/')
		);

```

\#####Deleting a webhook

```
$result = $managementSDK->webhooks()->delete('WEBHOOK_ID');

```

\#####Webhook Payload Builder

ParametersDescriptionurlThe callback URL for the webhook\###What's not implemented?

- **[Synchronization](https://www.contentful.com/developers/documentation/content-delivery-api/#sync)**.
- **The Preview API**.
- **Organizations**.

\###Contributing

**See a typo or a bug?** Make a pull request.
**What a new feature?** Make a pull request.
**Want a new feature and don't know how to build it?** You can always ask, I might be game if I think it's a good enough idea.

\####How you can help I'm going to make issues for features that I would like implemented. I'll assign them to myself if I plan to take to build them out. If I leave them unasigned, please step up and take it!

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 93.2% 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 ~31 days

Recently: every ~37 days

Total

6

Last Release

3916d ago

Major Versions

0.0.5 → 1.02015-08-29

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5910297?v=4)[Craig Wann](/maintainers/incraigulous)[@incraigulous](https://github.com/incraigulous)

---

Top Contributors

[![incraigulous](https://avatars.githubusercontent.com/u/5910297?v=4)](https://github.com/incraigulous "incraigulous (55 commits)")[![vburghelea](https://avatars.githubusercontent.com/u/1913582?v=4)](https://github.com/vburghelea "vburghelea (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/incraigulous-contentful-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/incraigulous-contentful-sdk/health.svg)](https://phpackages.com/packages/incraigulous-contentful-sdk)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

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