Skip to content

Instantly share code, notes, and snippets.

@Beej126
Last active November 18, 2021 22:31
Show Gist options
  • Save Beej126/fef02524a541d0d22532bf08ac6fa90c to your computer and use it in GitHub Desktop.
Save Beej126/fef02524a541d0d22532bf08ac6fa90c to your computer and use it in GitHub Desktop.
Hacking instaTeam web api
/////////////////////////////////////////////////////////////////////////////////////////
//first some helper functions to tee up one last clean routine at the bottom
//from: https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep/39914235#39914235
const sleep = s => new Promise(resolve => setTimeout(resolve, s * 1000));
//from:https://stackoverflow.com/questions/37576685/using-async-await-with-a-foreach-loop/49432189#49432189
Array.prototype.forEachAsync = async function (fn) { for (let t of this) { await fn(t) } }
//get data
const instaGet = url => fetch(url).then(response => response.json());
//post data
const instaPost = (url, dataObj) => fetch(url, { method: "POST", headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(dataObj) }).then(response => response.json()).then(result => console.log(result));
/////////////////////////////////////////////////////////////////////////////////////////
//get the full list of scheduled events
const fullSchedule = await instaGet("/api/team/schedule/list?v=2&paidEvents=0");
//flatten out their nested datastructure into an clean array of event objects
const events = fullSchedule.schedulesByDate.map(s => s.schedules).flat();
//attendance === 3 means not yet attending
//so this final expression filters on those events not yet booked,
//and calls the web api to flip her on for attending
await events.filter(e => e.childrenAttendance[0].attendance === 3).forEachAsync(async (e) => {
console.log("attend " +e.scheduleId+ " posting...");
await instaPost("/api/team/schedule/attend", {
"scheduleId": e.scheduleId,
"attend": "yes", // **** here's the beef! *****************************************************
"memberId": "xxxxxxx"
});
await sleep(2);
});
console.log("DONE!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment