@@ -557,9 +557,9 @@ if ($response->isOk()) {
557
557
Now we want to upload a new image, and then create a new simple story that includes the new image.
558
558
559
559
``` php
560
- use Storyblok\ManagementApi\Data\StoryblokData;
561
560
use Storyblok\ManagementApi\Data\Story;
562
561
use Storyblok\ManagementApi\ManagementApiClient;
562
+ use Storyblok\ManagementApi\Data\StoryComponent;
563
563
564
564
$client = new ManagementApiClient($storyblokPersonalAccessToken);
565
565
@@ -569,23 +569,20 @@ $assetApi = new AssetApi($client, $spaceId);
569
569
570
570
echo "UPLOADING ASSET..." . PHP_EOL;
571
571
$response = $assetApi->upload("image.png");
572
- /** @var AssetData $assetCreated */
573
572
$assetCreated = $response->data();
574
573
echo "Asset created, ID: " . $assetCreated->id() . PHP_EOL;
575
574
576
575
echo "PREPARING STORY DATA..." . PHP_EOL;
577
- $content = new StoryblokData();
578
- $content->set("component", "article-page");
576
+ $content = new StoryComponent("article-page");
579
577
$content->set("title", "New Article");
580
578
$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
+ );
589
586
590
587
echo "CREATING STORY..." . PHP_EOL;
591
588
$response = $storyApi->create($story);
0 commit comments