Skip to content

Instantly share code, notes, and snippets.

@onefriendaday
Created June 14, 2019 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onefriendaday/9db63406a47cc79d0beb35d3f6b29b5c to your computer and use it in GitHub Desktop.
Save onefriendaday/9db63406a47cc79d0beb35d3f6b29b5c to your computer and use it in GitHub Desktop.
Get all stories
const StoryblokClient = require('storyblok-js-client')
const Storyblok = new StoryblokClient({
token: 'TOKEN'
})
const Sync = {
getAll(page) {
return Storyblok.get(`stories`, {
per_page: 25,
page: page
})
},
async getAllStories() {
var page = 1
var res = await this.getAll(page)
var all = res.data.stories
var total = res.total
var lastPage = Math.ceil((res.total / 25))
while (page < lastPage){
page++
res = await this.getAll(page)
res.data.stories.forEach((story) => {
all.push(story)
})
}
return all
}
}
Sync.getAllStories()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment