Skip to content

Instantly share code, notes, and snippets.

@DominikAngerer
Last active February 9, 2023 17:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominikAngerer/50b030ddf2b04c4377f642c85e7e4a1a to your computer and use it in GitHub Desktop.
Save DominikAngerer/50b030ddf2b04c4377f642c85e7e4a1a to your computer and use it in GitHub Desktop.
Storyblok: How to publish all content entries in one folder
// # Install Dependencies: ---------------------------------------------------------------
// npm install storyblok-js-client
// # Execute with: -----------------------------------------------------------------------
// node storyblok-publish-all-in-folder.js
// # Configure: --------------------------------------------------------------------------
// ID of space your folder is located in
const space_id = 51455
// ID of folder (can be found in the URL in the storyblok app
// https://app.storyblok.com/#!/me/spaces/51455/stories/0/0/index/466856
// /\ this one
const folder_id = 466856
// Get it here: https://app.storyblok.com/#!/me/account
const oauth_token = 'YOUR_OAUTH_TOKEN'
// The script: --------------------------------------------------------------------------
const StoryblokClient = require('storyblok-js-client')
let Storyblok = new StoryblokClient({
oauthToken: oauth_token
})
const StoryblokIterator = {
getAll(page) {
return Storyblok.get('spaces/' + space_id + '/stories', {
per_page: 25,
with_parent: folder_id,
page: page,
version: 'draft'
})
}
}
async function publishAllStories() {
let page = 1
let res = await StoryblokIterator.getAll(page)
console.log(res)
let all = res.data.stories
let total = res.total
let lastPage = Math.ceil((res.total / 25))
while (page < lastPage) {
page++
res = await StoryblokIterator.getAll(page)
res.data.stories.forEach((story) => {
all.push(story)
})
}
for (let i = 0; i < all.length; i++) {
console.log('Publishing: ', all[i].name)
try {
let res = await Storyblok.get('spaces/' + space_id + '/stories/' + all[i].id + '/publish')
} catch (e) {
console.log(e.response.data)
}
}
return all
}
publishAllStories().then((result) => {
console.log('Finished')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment