Last active
June 8, 2023 10:40
-
-
Save tsuki-lab/1c3e9b94cdde3e6381b8423191fb35cb to your computer and use it in GitHub Desktop.
microCMSで全件取得する
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 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