Last active
January 31, 2023 04:35
-
-
Save ggorlen/0977195c405787c44453df61405ea71b to your computer and use it in GitHub Desktop.
Get all Codementor sessions
This file contains hidden or 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 fs = require("node:fs/promises"); | |
| const url = "https://dev.codementor.io/api/sessions"; | |
| const apiKey = ""; | |
| (async () => { | |
| const sessions = []; | |
| for (let startingAfter = "";;) { | |
| const response = await fetch(`${url}?starting_after=${startingAfter}`, { | |
| headers: { | |
| "x-codementor-api-key": apiKey | |
| } | |
| }); | |
| if (!response.ok) { | |
| throw Error(response.statusText); | |
| } | |
| const {data, has_more} = await response.json(); | |
| if (!has_more) { | |
| break; | |
| } | |
| startingAfter = data.at(-1).id; | |
| sessions.push(...data); | |
| } | |
| await fs.writeFile("cm-sessions.json", JSON.stringify(sessions)); | |
| })() | |
| .catch(error => console.log(error)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment