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

ActiveLibrary[API Development](/categories/api)

contentful/contentful-management
================================

SDK for the Contentful Content Management API

v4.1.3(4mo ago)8532.2k↓15.1%19[5 PRs](https://github.com/contentful/contentful-management.php/pulls)1MITPHPPHP ^8.0CI passing

Since Sep 12Pushed 1mo ago30 watchersCompare

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

READMEChangelog (10)Dependencies (10)Versions (41)Used By (1)

contentful-management.php
=========================

[](#contentful-managementphp)

[![Packagist](https://camo.githubusercontent.com/aa8e578f3243def252c9fa65630e860fe3966c3fa55e48c14eefbf278c17056d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f6e74656e7466756c2f636f6e74656e7466756c2d6d616e6167656d656e742e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/contentful/contentful-management)[![PHP version](https://camo.githubusercontent.com/73e5d63002f0e92b7270d3f51e7dda6f014f575f711a69349769c68dd4185366/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636f6e74656e7466756c2f636f6e74656e7466756c2d6d616e6167656d656e742e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/contentful/contentful-management)[![Packagist](https://camo.githubusercontent.com/08ff386616b4b059770d9b295757060f441d4f7bb07dd4d12529c4557aedb81a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636f6e74656e7466756c2f636f6e74656e7466756c2d6d616e6167656d656e742e7068702e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/contentful/contentful-management.php)[![CircleCI](https://camo.githubusercontent.com/96921534f3aa059856d6b7dac844f85c63d88f8e2fa6c5297204d5d54782301f/68747470733a2f2f636972636c6563692e636f6d2f67682f636f6e74656e7466756c2f636f6e74656e7466756c2d6d616e6167656d656e742e7068702e7376673f7374796c653d736869656c64)](https://circleci.com/gh/contentful/contentful-management.php)

> PHP SDK for [Contentful's](https://www.contentful.com) Content Management API. The SDK requires at least PHP 7.2 or PHP 8.0 and up.

Setup
-----

[](#setup)

Add this package to your application by using [Composer](https://getcomposer.org/) and executing the following command:

```
composer require contentful/contentful-management
```

Then, if you haven't already, include the Composer autoloader:

```
require_once 'vendor/autoload.php';
```

Basic concepts
--------------

[](#basic-concepts)

The first thing that needs to be done is initiating an instance of `Contentful\Management\Client` by giving it an access token. All actions performed using this instance of the `Client` will be performed with the privileges of the user this token belongs to.

```
$client = new \Contentful\Management\Client('access-token');
```

When working with space-scoped or environment-scoped resources, you can use proxies. They are lazy-references to a space or an environment, and they allow you to avoid repeating the space and environment ID when making API calls:

```
// Without space proxy
$deliveryApiKeys = $client->getDeliveryApiKeys($spaceId);
$roles = $client->getRoles($spaceId);
// With space proxy
$spaceProxy = $client->getSpaceProxy($spaceId);
$deliveryApiKeys = $spaceProxy->getDeliveryApiKeys();
$roles = $spaceProxy->getRoles();

// Without environment proxy
$assets = $client->getAssets($spaceId, $environmentId);
$entries = $client->getEntries($spaceId, $environmentId);
// With environment proxy
$environmentProxy = $client->getEnvironmentProxy($spaceId, $environmentId);
$assets = $environmentProxy->getAssets();
$entries = $environmentProxy->getEntries();
```

Usage
-----

[](#usage)

- [Api Keys](#api-keys)
- [Assets](#assets)
- [Content types and content type snapshots](#content-types-and-content-type-snapshots)
- [Editor interfaces](#editor-interfaces)
- [Entries and entry snapshots](#entries-and-entry-snapshots)
- [Environments](#environments)
- [Locales](#locales)
- [Organizations](#organizations)
- [Personal access tokens](#personal-access-tokens)
- [Roles](#roles)
- [Spaces](#spaces)
- [Space memberships](#space-memberships)
- [Uploads](#uploads)
- [UI extensions](#ui-extensions)
- [User](#users)
- [Webhooks](#webhooks)
- [Rate limits and retrying](#rate-limits-and-retrying)

### Api Keys

[](#api-keys)

Fetching:

```
$deliveryApiKeys = $spaceProxy->getDeliveryApiKeys();
$deliveryApiKey = $spaceProxy->getDeliveryApiKey($deliveryApiKeyId);

echo $deliveryApiKey->getSystemProperties()->getId();
echo $deliveryApiKey->getName();
echo $deliveryApiKey->getAccessToken();
$previewApiKeyLink = $deliveryApiKey->getPreviewApiKey();

$previewApiKey = $spaceProxy->resolveLink($previewApiKeyLink);
echo $previewApiKey->getAccessToken();
```

Creating and modifying:

```
$deliveryApiKey = new \Contentful\Management\Resource\DeliveryApiKey('Mobile');

$spaceProxy->create($deliveryApiKey);
echo $deliveryApiKey->getSystemProperties()->getId();
echo $deliveryApiKey->getAccessToken();

$deliveryApiKey->delete();
```

### Assets

[](#assets)

Fetching:

```
$assets = $environmentProxy->getAssets();
// Optionally, pass a query object
$query = (new \Contentful\Management\Query())
    ->setLimit(5);
$assets = $environmentProxy->getAssets($query);

$asset = $environmentProxy->getAsset($assetId);

echo $asset->getSystemProperties()->getId();
echo $asset->getTitle('en-US');
```

Creating and modifying:

```
$asset = new \Contentful\Management\Resource\Asset();
$file = new \Contentful\Core\File\RemoteUploadFile('Contentful.svg', 'image/svg+xml', $url);
$asset->setTitle('en-US', 'My asset')
    ->setDescription('en-US', 'My description')
    ->setFile('en-US', $file);

$environmentProxy->create($asset);

// Omit the locale to process the files for all locales
$asset->process('en-US');

$asset->setDescription('en-US', 'An even better description');
$asset->update();

$asset->archive();
$asset->unarchive();

$asset->publish();
$asset->unpublish();

$asset->delete();
```

### Content types and content type snapshots

[](#content-types-and-content-type-snapshots)

Fetching:

```
$contentTypes = $environmentProxy->getContentTypes();
// Optionally, pass a query object
$query = (new \Contentful\Management\Query())
    ->setLimit(5);
$contentTypes = $environmentProxy->getContentTypes($query);

$contentType = $environmentProxy->getContentType($contentTypeId);

echo $contentType->getSystemProperties()->getId();
echo $contentType->getName();

// Fetch the published version of content types
$contentTypes = $environmentProxy->getPublishedContentTypes($query);
$contentType = $environmentProxy->getPublishedContentType($contentTypeId);

// Fetch snapshots from a content type, or from an environment proxy
$snapshots = $contentType->getSnapshots();
$snapshot = $contentTy->getSnapshot($snapshotId);

$snapshots = $environmentProxy->getContentTypeSnapshots($contentTypeId);
$snapshot = $environmentProxy->getContentTypeSnapshot($contentTypeId, $snapshotId);
```

Creating and modifying:

```
$contentType = new \Contentful\Management\Resource\ContentType('Blog Post');
$contentType->setDescription('My description');
$contentType->addNewField('Symbol', 'title', 'Title');
$contentType->addNewField('Text', 'body', 'Body');

$customContentTypeId = 'blogPost';
$environmentProxy->create($contentType, $customContentTypeId);

$contentType->addNewField('Date', 'publishedAt', 'Published At');
$contentType->update();

$contentType->publish();
$contentType->unpublish();

$contentType->delete();
```

### Editor interfaces

[](#editor-interfaces)

Fetching and updating

```
$editorInterface = $environmentProxy->getEditorInterface($contentTypeId);

$control = $editorInterface->getControl('website');
$control->setWidgetId('urlEditor');

$editorInterface->update();
```

### Entries and entry snapshots

[](#entries-and-entry-snapshots)

Fetching:

```
$entries = $environmentProxy->getEntries();
// Optionally, pass a query object
$query = (new \Contentful\Management\Query())
    ->setLimit(5);
$entries = $environmentProxy->getEntries($query);

$entry = $environmentProxy->getEntry($entryId);

echo $entry->getSystemProperties()->getId();
echo $entry->getField('title', 'en-US');

// Fetch snapshots from an entry, or from an environment proxy
$snapshots = $entry->getSnapshots();
$snapshot = $entry->getSnapshot($snapshotId);

$snapshots = $environmentProxy->getEntrySnapshots($contentTypeId);
$snapshot = $environmentProxy->getEntrySnapshot($entryId, $snapshotId);
```

Creating and modifying:

```
$entry = new \Contentful\Management\Resource\Entry($contentTypeId);
$entry->setField('title', 'en-US', 'My awesome blog post');
$entry->setField('body', 'en-US', 'Something something...');

//Add existing assets
$images = [
    new \Contentful\Core\Api\Link('Example-existing-asset-id', 'Asset'),
    new \Contentful\Core\Api\Link('Example-existing-asset-id-2', 'Asset'),
];
$entry->setField('productImages', 'en-US', $images);

$environmentProxy->create($entry);

$entry->setField('body', 'en-US', 'Updated body');
$entry->update();

$entry->archive();
$entry->unarchive();

$entry->publish();
$entry->unpublish();

$entry->delete();
```

### Environments

[](#environments)

Fetching:

```
$environments = $spaceProxy->getEnvironments();
// Optionally, pass a query object
$query = (new \Contentful\Management\Query())
    ->setLimit(5);
$environments = $spaceProxy->getEnvironments($query);

$environment = $spaceProxy->getEnvironment($environmentId);

echo $environment->getSystemProperties()->getId();
echo $environment->getName();
```

Creating and modifying:

```
$environment = new \Contentful\Management\Resource\Environment('QA');
$spaceProxy->create($environment);

$environmentId = $environment->getSystemProperties()->getId();

// An environment might take a while to create,
// depending on the size of the master environment,
// so it might be a good idea to poll it until it's ready.
do {
    $environment = $spaceProxy->getEnvironment($environmentId);
    $status = $environment->getSystemProperties()->getStatus()->getId();
} while ($status !== 'ready');

$environment->delete();
```

Creating an environment with a different source:

```
$environment = new \Contentful\Management\Resource\Environment('QA','source-env-id');
$spaceProxy->create($environment);

// An environment might take a while to create,
// depending on the size of the master environment,
// so it might be a good idea to poll it until it's ready.
do {
    $environment = $spaceProxy->getEnvironment($environmentId);
    $status = $environment->getSystemProperties()->getStatus()->getId();
} while ($status !== 'ready');

$environment->delete();
```

### Locales

[](#locales)

Fetching:

```
$locales = $environmentProxy->getLocales();
// Optionally, pass a query object
$query = (new \Contentful\Management\Query())
    ->setLimit(5);
$locales = $environmentProxy->getLocales($query);

$locale = $environmentProxy->getLocale($localeId);

echo $locale->getSystemProperties()->getId();
echo $locale->getName();
echo $locale->getCode();
```

Creating and modifying:

```
$locale = new \Contentful\Management\Resource\Locale('English (United States)', 'en-US');
$environmentProxy->create($locale);

$locale->delete();
```

### Organizations

[](#organizations)

Fetching:

```
$organizations = $client->getOrganizations();
$organization = $organizations[0];

echo $organization->getSystemProperties()->getId();
echo $organization->getName();
```

### Personal access tokens

[](#personal-access-tokens)

Fetching:

```
$personalAccessTokens = $client->getPersonalAccessTokens();
// Optionally, pass a query object
$personalAccessTokens = (new \Contentful\Management\Query())
    ->setLimit(5);
$personalAccessTokens = $client->getPersonalAccessTokens($query);

$personalAccessToken = $client->getPersonalAccessToken($personalAccessTokenId);

echo $personalAccessToken->getSystemProperties()->getId();
echo $personalAccessToken->getName();
```

Creating and modifying:

```
$readOnly = false;
$personalAccessToken = new \Contentful\Management\Resource\PersonalAccessToken('Development access token', $readOnly);
$client->create($personalAccessToken);

// For security reasons, the actual token will only be available after creation.
echo $personalAccessToken->getToken();

$personalAccessToken->revoke();
```

### Roles

[](#roles)

Fetching:

```
$roles = $spaceProxy->getRoles();
// Optionally, pass a query object
$query = (new \Contentful\Management\Query())
    ->setLimit(5);
$roles = $spaceProxy->getRoles($query);

$role = $spaceProxy->getRole($roleId);

echo $role->getSystemProperties()->getId();
echo $role->getName();
```

Creating and modifying:

```
$role = new \Contentful\Management\Resource\Role('Publisher');

$policy = new \Contentful\Management\Resource\Policy('allow', 'publish');
$role->addPolicy($policy);

$constraint = new \Contentful\Management\Resource\Role\Constraint\AndConstraint([
    new \Contentful\Management\Resource\Role\Constraint\EqualityConstraint('sys.type', 'Entry'),
    new \Contentful\Management\Resource\Role\Constraint\EqualityConstraint('sys.type', 'Asset'),
]);
$policy->setConstraint($constraint);

$spaceProxy->create($role);

$policy->delete();
```

### Spaces

[](#spaces)

Fetching:

```
$spaces = $client->getSpaces();
// Optionally, pass a query object
$query = (new \Contentful\Management\Query())
    ->setLimit(5);
$spaces = $client->getSpaces($query);

$space = $client->getSpace($spaceId);

echo $space->getSystemProperties()->getId();
echo $space->getName();
```

Creating and modifying:

```
$space = new \Contentful\Management\Resource\Space('Website', $organizationId, $defaultLocaleCode);
$client->create($space);

$space->delete();
```

### Space memberships

[](#space-memberships)

Fetching:

```
$spaceMemberships = $spaceProxy->getSpaceMemberships();
// Optionally, pass a query object
$query = (new \Contentful\Management\Query())
    ->setLimit(5);
$spaceMemberships = $spaceProxy->getSpaceMemberships($query);

$spaceMembership = $spaceProxy->getSpaceMembership($spaceMembershipId);

echo $spaceMembership->getSystemProperties()->getId();
echo $spaceMembership->getUser()->getId();
```

Creating and modifying:

```
$spaceMembership = new \Contentful\Management\Resource\SpaceMembership();
$spaceMembership->setEmail($userEmail)
    ->setAdmin(false)
    ->addRoleLink($roleId);
$spaceProxy->create($spaceMembership);

$spaceMembership->delete();
```

### Uploads

[](#uploads)

Fetching:

```
$upload = $spaceProxy->getUpload($uploadId);

echo $upload->getSystemProperties()->getId();
```

Creating and modifying:

```
// You can pass as argument an fopen resource, an actual string, or a PSR-7 compatible stream
$upload = new \Contentful\Management\Resource\Upload(\fopen($myFile, 'r'));
$spaceProxy->create($upload);

$asset = new \Contentful\Management\Resource\Asset();
// To use the upload as an asset, you need to supply an asset name and a mime type
$asset->setFile('en-US', $upload->asAssetFile('my-asset-name.png', 'image/png'));

$environmentProxy->create($asset);

$asset->process();

$upload->delete();
```

### UI extensions

[](#ui-extensions)

Fetching:

```
$extensions = $environmentProxy->getExtensions();
// Optionally, pass a query object
$query = (new \Contentful\Management\Query())
    ->setLimit(5);
$extensions = $environmentProxy->getExtensions($query);

$extension = $environmentProxy->getExtension($extensionId);

echo $extension->getSystemProperties()->getId();
echo $extension->getName();
```

Creating and modifying:

```
$extension = new \Contentful\Management\Resource\Extension('My awesome extension');
$extension->setSource('https://www.example.com/extension-source')
    ->addNewFieldType('Symbol');

$environmentProxy->create($extension);

$extension->addNewFieldType('Link', ['Entry']);
$extension->update();

$extension->delete();
```

### Users

[](#users)

Fetching:

```
$user = $client->getUserMe();

echo $user->getSystemProperties()->getId();
echo $user->getEmail();
```

### Webhooks

[](#webhooks)

Fetching:

```
$webhooks = $spaceProxy->getWebhooks();
// Optionally, pass a query object
$query = (new \Contentful\Management\Query())
    ->setLimit(5);
$webhooks = $spaceProxy->getWebhooks($query);

$webhook = $spaceProxy->getWebhook($webhookId);

echo $webhook->getSystemProperties()->getId();
echo $webhook->getName();

// You can get calls and health from a webhook or from a space proxy
$calls = $webhook->getCalls();
$call = $webhook->getCall($callId);
$health = $webhook->getHealth();

$calls = $spaceProxy->getWebhookCalls($webhookId);
$call = $spaceProxy->getWebhookCall($webhookId, $callId);
$health = $spaceProxy->getWebhookHealth($webhookId);

echo $call->getStatusCode();
echo $call->getUrl();
echo $call->getEventType();

echo $health->getTotal();
echo $health->getHealthy();
```

Creating and modifying:

```
$webhook = new \Contentful\Management\Resource\Webhook('Publish webhook', $url, ['Entry.publish']);
$spaceProxy->create($webhook);

$webhook->addTopic('Asset.publish');
$webhook->update();

$webhook->delete();
```

### Rate limits and retrying

[](#rate-limits-and-retrying)

Some API calls are subject to rate limiting as described [here](https://www.contentful.com/developers/docs/technical-limits/). The SDK can be instructed to retry a call for a number of times via the max\_rate\_limit\_retries option:

```
$client = new \Contentful\Management\Client('KEY',['max_rate_limit_retries' => 2]);
$proxy = $client->getSpaceProxy('SPACE_ID');
$envName = uniqid();
$env = new \Contentful\Management\Resource\Environment($envName);
$proxy->create($env); //this call will retry two times (so three calls couting the original one), before throwing an exception
```

If the retry should happen in more than 60 seconds (as defined by the X-Contentful-RateLimit-Second-Remaining header [here](https://www.contentful.com/developers/docs/references/content-management-api/#/introduction/api-rate-limits) ), the call will throw a RateWaitTooLongException exception. This was implemented so that your scripts do not run for too long.

Contributinng
-------------

[](#contributinng)

PRs are welcome! If you want to develop locally, however, you will need to install with `--ignore-platform-reqs`, as one of the libraries used for testing does currently not officially support PHP8.

About Contentful
----------------

[](#about-contentful)

[Contentful](https://www.contentful.com) is a content management platform for web applications, mobile apps and connected devices. It allows you to create, edit &amp; manage content in the cloud and publish it anywhere via powerful API. Contentful offers tools for managing editorial teams and enabling cooperation between organizations.

License
-------

[](#license)

Copyright (c) 2015-2019 Contentful GmbH. Code released under the MIT license. See [LICENSE](LICENSE) for further details.

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance83

Actively maintained with recent releases

Popularity46

Moderate usage in the ecosystem

Community29

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 57.6% 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 ~132 days

Recently: every ~173 days

Total

24

Last Release

121d ago

Major Versions

0.9.0-beta2 → 1.0.0-beta12018-03-26

1.0.0 → 2.0.02019-01-25

2.2.1 → 3.0.02020-03-13

3.2.0 → 4.0.02022-01-21

PHP version history (5 changes)v0.9.0-beta1PHP ^7.0

3.0.0PHP ^7.2

3.2.0PHP ^7.2|^8.0

4.0.0PHP ^7.4|^8.0

4.1.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/6caf49052fd43966f7e5c1a6e78e4a9830f9dd014470be9f5da0736d141c0ea5?d=identicon)[mariobodemann](/maintainers/mariobodemann)

![](https://www.gravatar.com/avatar/c0d178c1c40db8c7e92e9fe71e0f2ef461d683679ae69275adf6661c8f3b8b67?d=identicon)[contentful](/maintainers/contentful)

---

Top Contributors

[![dborsatto](https://avatars.githubusercontent.com/u/94651?v=4)](https://github.com/dborsatto "dborsatto (242 commits)")[![realityking](https://avatars.githubusercontent.com/u/628508?v=4)](https://github.com/realityking "realityking (59 commits)")[![pgrigoruta](https://avatars.githubusercontent.com/u/1782518?v=4)](https://github.com/pgrigoruta "pgrigoruta (55 commits)")[![Sebb767](https://avatars.githubusercontent.com/u/4084001?v=4)](https://github.com/Sebb767 "Sebb767 (51 commits)")[![whitelisab](https://avatars.githubusercontent.com/u/62958907?v=4)](https://github.com/whitelisab "whitelisab (3 commits)")[![yadakhov](https://avatars.githubusercontent.com/u/146636?v=4)](https://github.com/yadakhov "yadakhov (2 commits)")[![jjolton-contentful](https://avatars.githubusercontent.com/u/145477871?v=4)](https://github.com/jjolton-contentful "jjolton-contentful (2 commits)")[![mariobodemann](https://avatars.githubusercontent.com/u/1162562?v=4)](https://github.com/mariobodemann "mariobodemann (2 commits)")[![matthew-contentful](https://avatars.githubusercontent.com/u/52446913?v=4)](https://github.com/matthew-contentful "matthew-contentful (2 commits)")[![ghepting](https://avatars.githubusercontent.com/u/492573?v=4)](https://github.com/ghepting "ghepting (1 commits)")[![forged-request](https://avatars.githubusercontent.com/u/104775415?v=4)](https://github.com/forged-request "forged-request (1 commits)")

---

Tags

contentfulphpsdk

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[contentful/contentful

SDK for the Contentful Content Delivery API

1173.9M18](/packages/contentful-contentful)[jane-php/jane-php

All jane libraries into one repository

678254.7k4](/packages/jane-php-jane-php)[code-lts/doctum

Doctum, a PHP API documentation generator. Fork of Sami

35077.9k31](/packages/code-lts-doctum)[worksome/graphlint

A static analysis tool for GraphQL

13189.4k](/packages/worksome-graphlint)[rekalogika/mapper

An object mapper for PHP and Symfony. Maps an object to another object. Primarily used for transforming an entity to a DTO and vice versa.

3847.7k1](/packages/rekalogika-mapper)

PHPackages © 2026

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