Download the PHP package storyblok/php-client without Composer

On this page you can find all versions of the php package storyblok/php-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-client

Storyblok Logo

Storyblok PHP Client

This is the official Storyblok PHP client to easily access the Content Delivery API and Management API.

Join the Storyblok Discord Community Follow @Storyblok
Follow @Storyblok

🚀 Usage

With the Storyblok PHP client you can integrate two kinds of Storyblok APIs:

In this README file you will find information for using the Storyblok PHP client, like:

Installing the Storyblok PHP client

You can install the Storyblok PHP Client via composer. Storyblok's PHP client requires PHP version 7.3 to 8.3. The suggestion is to use an actively supported version of PHP (8.2 and 8.3).

If you want to install the stable release of Storyblok PHP client you can launch:

If you want to install the current development release, you can add the version dev-master:

For executing the command above, you need to have composer installed on your development environment. If you need to install Composer, you can follow the official Composer documentation:

We suggest using the latest version of PHP.

Management API

The Storyblok\ManagementClient instance

Now we are going to see how to initialize the Storyblok Management Client for the Management API](https://www.storyblok.com/docs/api/management) with your Personal OAuth Token. The Personal OAuth token is taken from the "My Account" section. This token is used for read and write operations. The class for using the Management API is the Storyblok\ManagementClient class. When you are going to instance a new ManagementClient object you can use the Personal OAuth Token as a parameter.

Now, you have the ManagementClient object ($managementClient), you can start to manage your Storyblok data.

Retrieve data, get() method

If you need to retrieve data, you have to perform an HTTP request with the GET method. The ManagementClient provides a get() method for performing the HTTP request. The mandatory parameter is the path of the API ( for example spaces/<yourSpaceId/stories). The path defines which endpoint you want to use.

For retrieving a list of Stories:

With getBody() method you can access the body response, and then access the stories key, to access the story list.

Create data, post() method

If you need to create data, you have to perform an HTTP request with the POST method. The ManagementClient provides a post() method for performing the HTTP request. The mandatory parameter is the path of the API ( for example spaces/<yourSpaceId/stories/), and the Story payload. For creating a new story:

Update data, put() method

If you need to update data, you have to perform an HTTP request with PUT method. The ManagementClient provides a put() method for performing the HTTP request. The mandatory parameter is the path of the API ( for example spaces/<yourSpaceId/stories/<storyId>), and the Story payload. For updating the story:

Delete data, delete() method

If you need to delete data, you have to perform an HTTP request with the DELETE method. The ManagementClient provides a delete() method for performing the HTTP request. The mandatory parameter is the path of the API, defining also the identifier of the entry you want to delete ( for example spaces/<yourSpaceId/stories/<storyId>). For deleting a story:

Using spaces created in other regions for Management API

When creating a Space, you can select the EU, US, CA, AP region. The default region is EU.

For example: If you want to access a Space created in US region, you need to define the apiEndpoint parameter with api-us.storyblok.com value, and forcing the ssl option for using HTTPS protocol:

Now you have the Storyblok\ManagementClient instance, you can start managing data.

Content Delivery API

The Storyblok\Client instance

Now we are going to see how to initialize the Storyblok Client class for consuming the Content Delivery API V2, with the Access Token. You can retrieve the access token from the "Settings > Access Tokens" tab (in your space, in Stroyblok UI).

If you want to use an alias to refer to the Storyblok\Client class, you can use the use ... as ... statement:

Using spaces created in the other regions

When you create a Space, you can select the region: EU, US, CA or AP.

For example: If you want to access a Space created in US region, you need to define the apiRegion parameter with the us value (or US):

If you are still using PHP 7.x, you have to use the old notation (without named arguments):

Now you have the Storyblok\Client instance you can start consuming data.

Load a Story by slug

Load a Story by slug for a specific language

If are using the field-level translation, you can retrieve a story for a specific language via the language() method. The language method requires a string as a parameter with the code of the language.

Load Space information

If you need to access some space information like space identifier, space name, the latest version timestamp, or the list of configured languages you can use the spaces endpoint.

Because the PHP Client, with the current version, doesn't provide an helper for retrieving data from the space endpoint you can use the get() method for accessing the spaces/me path of the Content Delivery API. The only thing you need to remember is to set the second parameter for the get() method injecting the API parameters. Even if you didn't set any parameters, you have to send getApiParameters() as the second parameter for the get() method because the PHP client manages for you some core parameters like the token. This is because you are using the low-level method get().

Load a Story by UUID

The structure of the data returned by the getBody() of the getStoryByUuid() method, has the same structure of the getStoryBySlug() so: story, cv, rels, links.

Load a list of Stories

If you need to retrieve a list of stories you can use the getStories() method. You can use the parameter to filter the stories. For example, if you want to retrieve all entries from a specific folder you can use starts_with option in this way:

Under the hood, the starts_with option, filters entries by full_slug.

Load all entries

Because the response from Storyblok API could be paginated, you should walk through all the pages to collect all the entries. The Storyblok PHP Client provides you a helper named getAll() for retrieving all the entries. Under the hood, the getAll() method performs all the API call according to the pagination data (total, per page etc).

Example, retrieving all stories:

If you want to retrieve the array of the responses for each call:

Load a list of datasource entries

With the Storyblok\Client you have also the getDatasourceEntries() method for retrieving the list of key/values of the datasource:

If you want to receive also the dimension values besides the default values in one datasource entry you can use the option dimension when you call getDatasourceEntries() method. You could use dimensions for example when you are using datasource for storing a list of values and you want a translation for the values. In this case, you should create one dimension for each language.

Load a list of tags

Access to the Responses Headers

When you perform a request to Content Delivery API, you can access the headers of the HTTP response. For example, after you call the getStories() method (for retrieving a list of stories) you can access to the HTTP response headers via getHeaders() method:

Retrieving Draft or Published content

In a Web application where the query string is available, the content delivery client checks automatically the GET parameters:

If you want to override this "default" behavior, or you are in a non-web context (for example you are implementing a command line tool), to retrieve the draft content (for example a not yet published story) you have to use the editMode() method. If you want to retrieve the published content (for example a published story) you have to use the editMode(false) method with false parameter.

Managing cache

When you perform an API request you can use the caching mechanism provided by the Storyblok PHP client. When you initialize the Storyblok\Client you can set the cache provider. For example, using the setCache() method you can define the provider (for example filesystem) and an array of options. In case you are using the filesystem as storage of cache items, you can set the path with path option:

You can set a TTL value for the cache via default_lifetime option.

The caching mechanism uses under the hood the Symfony Cache package. So, you can use the Adapter supported the Symfony Cache. For example, for using a MySql database as cache storage, you can setup the connection via the PHP PDO class:

Clearing the cache (Optionally if using setCache)

In order to flush the cache when the user clicks publish, you need to listen to the published event in javascript or define a webhook in the space settings that clears the cache on your server.

In clear.php:

Generate a navigation tree

Nginx SSI - Server Side Includes

Use the following script if you have Nginx SSI enabled and experience issues with printing the _editable html comments directly to manually parse the Storyblok HTML editable comments: https://gist.github.com/DominikAngerer/ca61d41bae3afcc646cfee286579ad36

Relationships and Links Resolving

In order to resolve relations you can use the resolveRelations method of the client passing a comma separated list of fields:

Another example:

In order to resolve links, you can use the resolveLinks method passing the specific type of resolving you want to perform among url, story or link:

When using the CDN API V1, you can't resolve relationships of resolved entries and the resolved entries are injected in the field of the relationship. The same happens with links resolving. When using the CDN API V2 you can resolve also nested relationships in the resolved entries (just 2 levels deep), but the resolved entries are not injected in the fields, they are inserted in an array called rels which is in the root object. The resolved links will be placed in an array called links. In case you are using the API V2, to keep a consistent behaviour with the API V1, this client will inject the resolved entries and links inside the fields for you.

Code Quality

The package includes tools for tests and code formatting:

that executes:

🔗 Related Links

ℹī¸ More Resources

Support

Contributing

Please see our contributing guidelines and our code of conduct. This project use semantic-release for generate new versions by using commit messages and we use the Angular Convention to naming the commits. Check this question about it in semantic-release FAQ.

License

This repository is published under the MIT license.


All versions of php-client with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3.0
guzzlehttp/guzzle Version ^7.4
symfony/cache Version ^4.0|^5.0|^6.0|^7.0
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package storyblok/php-client contains the following files

Loading the files please wait ....