Skip to content

Instantly share code, notes, and snippets.

@ggorlen
Last active January 31, 2023 04:35
Show Gist options
  • Select an option

  • Save ggorlen/0977195c405787c44453df61405ea71b to your computer and use it in GitHub Desktop.

Select an option

Save ggorlen/0977195c405787c44453df61405ea71b to your computer and use it in GitHub Desktop.
Get all Codementor sessions
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