Skip to content

Instantly share code, notes, and snippets.

@tsuki-lab
Last active June 8, 2023 10:40
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 tsuki-lab/1c3e9b94cdde3e6381b8423191fb35cb to your computer and use it in GitHub Desktop.
Save tsuki-lab/1c3e9b94cdde3e6381b8423191fb35cb to your computer and use it in GitHub Desktop.
microCMSで全件取得する
const client = createClient({
serviceDomain: process.env.MICROCMS_DOMAIN,
apiKey: process.env.API_KEY
})
const getAllContents = async (offset=0, limit=10) => {
const data = await client.get({
endpoint: `{MICROCMS_ENDPOINT}`,
queries: {
offset,
limit
}
})
if (data.offset + data.limit <= data.totalCount) {
const contents = await getAllContents(data.offset + data.limit, data.limit)
return [ ...data.contents, ...contents ]
}
return data.contents
}
export { getAllContents }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment