Created
June 14, 2019 11:36
-
-
Save onefriendaday/9db63406a47cc79d0beb35d3f6b29b5c to your computer and use it in GitHub Desktop.
Get all stories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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