Skip to content

Commit 2da53a5

Browse files
committed
documenting createBulk method
1 parent 4973d8a commit 2da53a5

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Changelog
22

3-
## 0.0.4 - WIP
3+
## 0.0.4 - 2025-02-05
44

55
- Adding WorkflowStage Api class for handling workflow stages
6-
-
6+
- Adding bulk story creation with rate limit handling
7+
78
## 0.0.3 - 2025-02-03
89

910
- Adding helper methods for SpaceData (id(), updatedAt())

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,35 @@ $storyApi->publish($storyId);
297297
```
298298

299299

300+
### Creating stories in bulk
301+
You can create multiple stories using the `createBulk()` method, which processes an array of stories while managing rate limits through a retry mechanism that respects the '429' status code.
302+
303+
For example, if you have a CSV file containing content for new stories, you can use this method to efficiently create them.
304+
305+
```csv
306+
myslug-001;My Story 1 BULK;page
307+
myslug-002;My Story 2 BULK;page
308+
myslug-003;My Story 3 BULK;page
309+
```
310+
311+
Next, you can implement a script to load and parse the CSV file. In this case, we use `SplFileObject` and then call the `createBulk` method to process the data:
312+
313+
```php
314+
$storyApi = $client->storyApi($spaceId);
315+
$file = new SplFileObject("stories.csv");
316+
$file->setFlags(SplFileObject::READ_CSV);
317+
$file->setCsvControl(separator: ";");
318+
$stories = [];
319+
foreach ($file as $row) {
320+
list($slug, $name, $contentType) = $row;
321+
$story = new StoryData();
322+
$story->setName($name);
323+
$story->setSlug($slug);
324+
$story->setContentType($contentType);
325+
$stories[] = $story;
326+
}
327+
$createdStories = iterator_to_array($storyApi->createBulk($stories));
328+
```
300329

301330
## Handling users
302331

0 commit comments

Comments
 (0)