# CroctStoriesApi

Learn how to serve personalized content inside Storyblok stories.

This class decorates Storyblok's Stories API to serve personalized content inside your stories.

It implements the same [`StoriesApiInterface`](https://github.com/storyblok/php-content-api-client) as the API it wraps, so you can use it as a drop-in replacement. Every story it returns has its blocks linked to a Croct [slot](/explanation/slot) replaced with personalized content, converted to the Storyblok shape.

## Signature \[#signature]

The constructor has the following signature:

```php
public function __construct(
    StoriesApiInterface $api,
    Plug $plug,
    ?ContentResolver $resolver = null,
)
```

## Example

Here is a basic example of how to wrap your Stories API:

```php
<?php
use Croct\Plug\Croct;
use Croct\Plug\Storyblok\CroctStoriesApi;
use Storyblok\Api\StoriesApi;
use Storyblok\Api\StoryblokClient;

$plug = Croct::fromDotenv();

$client = new StoryblokClient(
    baseUri: 'https://api.storyblok.com',
    token: 'YOUR_ACCESS_TOKEN',
);

$stories = new CroctStoriesApi(new StoriesApi($client), $plug);

$response = $stories->bySlug('home');
```

Every read method, such as `bySlug`, `byId`, and `all`, returns stories with their linked blocks resolved. When a fetch fails, the block keeps its original content, so your pages never break.

## Parameters

The following list describes the constructor parameters:

- `api`: [`StoriesApiInterface`](https://github.com/storyblok/php-content-api-client)

  The Storyblok Stories API to decorate.

- `plug`: [`Plug`](/reference/sdk/php/api/core/plug)

  The Croct SDK instance used to fetch personalized content.

- `resolver`: `ContentResolver` (optional) (default: null)

  The resolver that converts Croct content to the Storyblok shape.

  This is an advanced customization point. The default resolver handles the standard content schema.
