> This page is for Contentful SDKs.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://contentful-staging.ferndocs.com/developers/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://contentful-staging.ferndocs.com/developers/docs/_mcp/server.

# Complete reference guide to the Delivery client library

> Complete reference guide to managing delivery client libraries for PHP by using three parameters, access token, space ID and environment ID.

## Complete reference guide to the Delivery client library

The first thing that needs to be done is initiating an instance of `Contentful\Delivery\Client` by giving it three parameters: an access token, a space ID, and an environment ID (which is optional and defaults to `master`).

```php
$client = new \Contentful\Delivery\Client($accessToken, $spaceId, $environmentId);
```

The client constructor also takes other optional parameters. This is the complete configuration:

```php
$client = new \Contentful\Delivery\Client(
    $accessToken,
    $spaceId,
    $environmentId = 'master',
    $options = null
);
```

## Usage

* [Assets](#assets)
* [Content types](#content-types)
* [Entries](#entries)
* [Environments and locales](#environment-and-locales)
* [Space](#space)

### Assets

| Name                                                                                                    | Fetch one                                     | Fetch collection                    |
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------- | ----------------------------------- |
| [Asset](https://contentful.github.io/contentful.php/api/master/Contentful/Delivery/Resource/Asset.html) | `$client->getAsset($assetId, $locale = null)` | `$client->getAssets($query = null)` |
| [File](https://contentful.github.io/contentful-core.php/api/master/Contentful/Core/File.html)           | `$asset->getFile()`                           | -                                   |

```php
$asset = $client->getAsset($assetId, 'en-US');
echo $asset->getTitle('en-US');
echo $asset->getDescription('en-US');
/** @var Contentful\Core\File\FileInterface $file */
$file = $asset->getFile('en-US');

$assets = $client->getAssets();
foreach ($assets as $asset) {
    echo $asset->getTitle('en-US')
}
```

### Content types

| Name                                                                                                                | Fetch one                                 | Fetch collection                          |
| ------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | ----------------------------------------- |
| [ContentType](https://contentful.github.io/contentful.php/api/master/Contentful/Delivery/Resource/ContentType.html) | `$client->getContentType($contentTypeId)` | `$client->getContentTypes($query = null)` |

```php
$contentType = $client->getContentType($contentTypeId);
echo $contentType->getName('en-US');

$contentTypes = $client->getContentTypes();
foreach ($contentTypes as $contentType) {
    echo $contentType->getName('en-US');
}
```

### Entries

| Name                                                                                                    | Fetch one                                     | Fetch collection                     |
| ------------------------------------------------------------------------------------------------------- | --------------------------------------------- | ------------------------------------ |
| [Entry](https://contentful.github.io/contentful.php/api/master/Contentful/Delivery/Resource/Entry.html) | `$client->getEntry($assetId, $locale = null)` | `$client->getEntries($query = null)` |

```php
$entry = $client->getEntry($assetId, 'en-US');
// Entries have magic getters which correspond to field names
// This assumes you have a field named "title"
echo $entry->getTitle('en-US');

$entries = $client->getEntries();
foreach ($entries as $entry) {
    echo $entry->getTitle('en-US')
}
```

### Environment and locales

| Name                                                                                                                | Fetch one                   | Fetch collection             |
| ------------------------------------------------------------------------------------------------------------------- | --------------------------- | ---------------------------- |
| [Environment](https://contentful.github.io/contentful.php/api/master/Contentful/Delivery/Resource/Environment.html) | `$client->getEnvironment()` | -                            |
| [Locale](https://contentful.github.io/contentful.php/api/master/Contentful/Delivery/Resource/Locale.html)           | -                           | `$environment->getLocales()` |

Environments in this client library are a virtual resource, which is used as a container for locales:

```php
$environment = $client->getEnvironment();

foreach ($environment->getLocales() as $locale) {
    /** @var \Contentful\Delivery\Resource\Locale $locale */
    echo $locale->getCode();
}
```

### Space

| Name                                                                                                    | Fetch one             | Fetch collection |
| ------------------------------------------------------------------------------------------------------- | --------------------- | ---------------- |
| [Space](https://contentful.github.io/contentful.php/api/master/Contentful/Delivery/Resource/Space.html) | `$client->getSpace()` | -                |

```php
$space = $client->getSpace();
echo $space->getName();
```