Created
March 1, 2021 03:32
-
-
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
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 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