Skip to content

Commit 4552052

Browse files
committed
Update README.md
1 parent d448dba commit 4552052

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,9 @@ if ($response->isOk()) {
557557
Now we want to upload a new image, and then create a new simple story that includes the new image.
558558

559559
```php
560-
use Storyblok\ManagementApi\Data\StoryblokData;
561560
use Storyblok\ManagementApi\Data\Story;
562561
use Storyblok\ManagementApi\ManagementApiClient;
562+
use Storyblok\ManagementApi\Data\StoryComponent;
563563

564564
$client = new ManagementApiClient($storyblokPersonalAccessToken);
565565

@@ -569,23 +569,20 @@ $assetApi = new AssetApi($client, $spaceId);
569569

570570
echo "UPLOADING ASSET..." . PHP_EOL;
571571
$response = $assetApi->upload("image.png");
572-
/** @var AssetData $assetCreated */
573572
$assetCreated = $response->data();
574573
echo "Asset created, ID: " . $assetCreated->id() . PHP_EOL;
575574

576575
echo "PREPARING STORY DATA..." . PHP_EOL;
577-
$content = new StoryblokData();
578-
$content->set("component", "article-page");
576+
$content = new StoryComponent("article-page");
579577
$content->set("title", "New Article");
580578
$content->set("body", "This is the content");
581-
$content->set("image.id", $assetCreated->id());
582-
$content->set("image.fieldtype", "asset");
583-
$content->set("image.filename",$assetCreated->filename());
584-
585-
$story = new Story();
586-
$story->setName("An Article");
587-
$story->setSlug("an-article-" . random_int(10000, 99999));
588-
$story->setContent($content->toArray());
579+
$content->setAsset("image", $assetCreated);
580+
581+
$story = new Story(
582+
"An Article",
583+
"an-article-" . random_int(10000, 99999),
584+
$content
585+
);
589586

590587
echo "CREATING STORY..." . PHP_EOL;
591588
$response = $storyApi->create($story);

0 commit comments

Comments
 (0)