Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jameswomack/9c04fa300d6367c7fb0b96e27214da70 to your computer and use it in GitHub Desktop.
Save jameswomack/9c04fa300d6367c7fb0b96e27214da70 to your computer and use it in GitHub Desktop.
Using the ManageBac API to retrieve a set of students across multiple classes
const fetch = require('node-fetch');
function classFetch (classId) {
return fetch(`https://api.managebac.com/v2/classes/${classId}/students`, {
headers: {
'auth-token': '{{}}'
}
})
.then(response =>
response.json()
.then(({student_ids}) =>
Promise.all(student_ids.map(id => {
return fetch(`https://api.managebac.com/v2/students/${id}`, {
headers: {
'auth-token': '{{}}'
}
})
.then(response =>
response.json())
.catch(console.error)
}))
)
)
.catch(console.error);
}
Promise.all(['11111555', '11111556'].map(classFetch))
.then(results => // we could send the results somehwre else if we wanted...
console.dir(
// collapse class[n]->students... into a shared set
results.reduce((acc, result) => [...acc, ...result], []),
{depth:Infinity,colors:true}
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment