class Client extends Client

Client class.

This class is responsible for querying Contentful's Content Management API.

Constants

VERSION

The current version of the SDK.

URI_MANAGEMENT

The default URI to which all requests should be made.

URI_UPLOAD

The special URI for uploading files.

Properties

Asset $asset
ContentType $contentType
ContentTypeSnapshot $contentTypeSnapshot
DeliveryApiKey $deliveryApiKey
EditorInterface $editorInterface
Entry $entry
EntrySnapshot $entrySnapshot
Extension $extension
Locale $locale
Organization $organization
PersonalAccessToken $personalAccessToken
PreviewApiKey $previewApiKey
PublishedContentType $publishedContentType
Role $role
Space $space
SpaceMembership $spaceMembership
Upload $upload
User $user
Webhook $webhook
WebhookCall $webhookCall
WebhookHealth $webhookHealth

Methods

__construct(string $token, string $currentSpaceId = null, array $options = [])

Client constructor.

getBuilder()

Returns the active ResourceBuilder instance.

setBuilder(ResourceBuilder $builder)

Sets the active ResourceBuilder instance.

string|null
getCurrentSpaceId()

Returns the space ID to which this client is currently bound.

setCurrentSpaceId(string $currentSpaceId = null)

Sets the space ID to which the client is currently bound.

getProxy(string $name, string $spaceId = null)

Returns a proxy instance responsible for querying certain endpoints.

__get(string $name)

Convenience method for accessing a proxy.

ResourceArray|ResourceInterface
getResource(string $uri, Query $query = null, array $options = [], ResourceInterface $resource = null)

Makes a GET call to an API endpoint, and returns the built object.

requestResource(string $method, string $uri, array $options = [], ResourceInterface $resource = null)

Requests an API resource and applies the result to the given object.

resolveLink(Link $link, string $spaceId = null)

Resolves a Link object to the actual resource.

getSdkName()

{@inheritdoc}

getSdkVersion()

{@inheritdoc}

getApiContentType()

{@inheritdoc}

getExceptionMap()

{@inheritdoc}

Details

at line 123
__construct(string $token, string $currentSpaceId = null, array $options = [])

Client constructor.

Parameters

string $token A oauth token or personal access token generated by Contentful
string $currentSpaceId Optionally, the default space ID for querying operations
array $options An array of options, with the following supported values: - guzzle: an instance of the Guzzle client - logger: a logger implementing \Contentful\Log\LoggerInterface - uriOverride: a string that will replace the default Contentful URI - builder: a custom ResourceBuilder instance

at line 141
ResourceBuilder getBuilder()

Returns the active ResourceBuilder instance.

Return Value

ResourceBuilder

at line 153
Client setBuilder(ResourceBuilder $builder)

Sets the active ResourceBuilder instance.

Parameters

ResourceBuilder $builder

Return Value

Client

at line 166
string|null getCurrentSpaceId()

Returns the space ID to which this client is currently bound.

It can be null, as certain operations are not done on a space level.

Return Value

string|null

at line 178
Client setCurrentSpaceId(string $currentSpaceId = null)

Sets the space ID to which the client is currently bound.

Parameters

string $currentSpaceId

Return Value

Client

at line 195
BaseProxy getProxy(string $name, string $spaceId = null)

Returns a proxy instance responsible for querying certain endpoints.

Parameters

string $name A valid proxy name, it will be resolved to a class in the namespace \Contentful\Management\Proxy
string $spaceId Optionally, a space ID required by proxies that query Contentful's endpoints on a space level

Return Value

BaseProxy An object extending BaseProxy

Exceptions

InvalidArgumentException

at line 229
BaseProxy __get(string $name)

Convenience method for accessing a proxy.

Allows for this usage.

$entry = $client->entries->get($entryId);

Attention: if no space ID is provided and the proxy requires one, it will throw an exception.

Parameters

string $name

Return Value

BaseProxy An object extending BaseProxy

See also

Client::getProxy()

at line 245
ResourceArray|ResourceInterface getResource(string $uri, Query $query = null, array $options = [], ResourceInterface $resource = null)

Makes a GET call to an API endpoint, and returns the built object.

Parameters

string $uri The API endpoint
Query $query Optionally, a \Contentful\Management\Query object defining query string parameters
array $options An array of options for the HTTP client
ResourceInterface $resource If a resource object is given, its properties will be overwritten

Return Value

ResourceArray|ResourceInterface

at line 264
requestResource(string $method, string $uri, array $options = [], ResourceInterface $resource = null)

Requests an API resource and applies the result to the given object.

Parameters

string $method The HTTP method
string $uri The API endpoint
array $options An array of options for the HTTP client
ResourceInterface $resource Optionally, an object whose properties will be overwritten

Resolves a Link object to the actual resource.

Parameters

Link $link A link object to a valid resource in Contentful
string $spaceId Optionally, a space ID to override the one currently in use

Return Value

ResourceInterface

at line 313
protected getSdkName()

{@inheritdoc}

at line 321
protected getSdkVersion()

{@inheritdoc}

at line 329
protected getApiContentType()

{@inheritdoc}

at line 337
protected getExceptionMap()

{@inheritdoc}