PHPackages                             storyblok/symfony-bundle - 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. storyblok/symfony-bundle

ActiveSymfony-bundle[API Development](/categories/api)

storyblok/symfony-bundle
========================

Symfony bundle for storyblok/php-management-api-client and storyblok/php-content-api-client

1.16.1(3mo ago)881.8k↓20.2%4[5 PRs](https://github.com/storyblok/symfony-bundle/pulls)MITPHPPHP &gt;=8.3CI passing

Since Jan 16Pushed 1mo ago7 watchersCompare

[ Source](https://github.com/storyblok/symfony-bundle)[ Packagist](https://packagist.org/packages/storyblok/symfony-bundle)[ RSS](/packages/storyblok-symfony-bundle/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (10)Dependencies (29)Versions (51)Used By (0)

 [![Storyblok Symfony Bundle](assets/php-symfony-bundle-github-repository.png)](assets/php-symfony-bundle-github-repository.png)Storyblok Symfony Bundle
========================

[](#storyblok-symfony-bundle)

Co-created with [SensioLabs](https://sensiolabs.com/), the creators of Symfony.

BranchPHPCode Coverage`master`[![PHP](https://github.com/sensiolabs-de/storyblok-bundle/actions/workflows/ci.yaml/badge.svg)](https://github.com/sensiolabs-de/storyblok-bundle/actions/workflows/ci.yaml)[![codecov](https://camo.githubusercontent.com/c665806e5b17f3b8d7cf18d583528da3a1a91849824e471b544d4004a83b5de4/68747470733a2f2f636f6465636f762e696f2f67682f73746f7279626c6f6b2f73796d666f6e792d62756e646c652f67726170682f62616467652e737667)](https://codecov.io/gh/storyblok/symfony-bundle)A Symfony bundle to integrate the [Storyblok headless CMS](https://www.storyblok.com/) with your Symfony application.

This bundle leverages the [storyblok/php-content-api-client](https://github.com/storyblok/php-content-api-client), a type-safe PHP SDK for Storyblok. It configures the Storyblok client and provides a Symfony Profiler extension for easier debugging and monitoring of Storyblok API interactions.

Installation
------------

[](#installation)

To install the bundle run:

```
composer require storyblok/php-content-api-client storyblok/symfony-bundle
```

Configuration
-------------

[](#configuration)

### Symfony Flex

[](#symfony-flex)

If you are using `symfony/flex`, the bundle will be automatically enabled and the configuration files will be added to your project.

### Manual Configuration

[](#manual-configuration)

If `symfony/flex` is not available, or you prefer manual setup, follow these steps:

1. **Add the Configuration**Add the following configuration to your `config/packages/storyblok.yaml`:

    ```
    storyblok:
      base_uri: '%env(STORYBLOK_API_BASE_URI)%'
      token: '%env(STORYBLOK_API_TOKEN)%'
    ```

    If you want to use the AssetsApi, you can also add the following configuration:

    ```
    storyblok:
      # ...
      assets_token: '%env(STORYBLOK_ASSETS_API_TOKEN)%'
    ```
2. **Set Environment Variables**Define the necessary environment variables in your `.env` file:

    ```
    STORYBLOK_API_BASE_URI=https://api.storyblok.com
    STORYBLOK_API_TOKEN=your_storyblok_api_token
    ```

Usage
-----

[](#usage)

### API Usage

[](#api-usage)

After setting up the bundle, you can use the Storyblok client within your Symfony application to interact with the Storyblok CMS API.

For detailed usage and examples, please refer to the [Storyblok API SDK documentation](https://github.com/sensiolabs-de/storyblok-api).

### Versions (`draft` and `published`)

[](#versions-draft-and-published)

Storyblok allows you to work with two versions of your content: `draft` and `published`. By default, the bundle uses the `published` version. If you want to use the `draft` version, you can set the `version` parameter in the configuration:

```
storyblok:
    # ...
    version: draft
```

### Webhooks

[](#webhooks)

Storyblok Webhooks allow your Symfony application to react to events like content changes. This bundle provides easy setup for handling these Webhooks.

#### Configuration

[](#configuration-1)

To enable Webhooks, add the following route to your application:

```
# config/routes/storyblok.yaml
storyblok_webhook:
    resource: '@StoryblokBundle/config/routes/webhook.php'

storyblok_content_type:
    resource: '@StoryblokBundle/config/routes/content_type.php'
```

This will make a route available at `/storyblok/webhook` to receive Webhook requests. For more details on how Webhooks work, check the [Storyblok Webhooks Documentation](https://www.storyblok.com/docs/guide/in-depth/webhooks).

#### Verifying Webhook Signatures (Security)

[](#verifying-webhook-signatures-security)

For security, you can enable the verification of Webhook signatures to ensure that the requests come from Storyblok. This is done by configuring a `webhook_secret`:

```
# config/packages/storyblok.yaml
storyblok:
    # ...
    webhook_secret: '%env(STORYBLOK_WEBHOOK_SECRET)%'
```

You'll need to set this secret in your `.env` file:

```
STORYBLOK_WEBHOOK_SECRET=your_webhook_secret
```

Once enabled, the bundle will automatically validate each Webhook request against this secret.

#### Handling Webhook Events

[](#handling-webhook-events)

To process Webhooks, implement the `WebhookHandlerInterface`. The bundle automatically registers any classes implementing this interface as Webhook handlers, no additional service configuration is required.

**Example Webhook Handler**

Here's an example of a Webhook handler that purges a Varnish cache whenever certain events occur (e.g., content published or deleted):

```
