Skip to content

Instantly share code, notes, and snippets.

@Explosion-Scratch
Created October 12, 2021 23:55
Show Gist options
  • Save Explosion-Scratch/154792ea7faf4254c9abdcd771e68868 to your computer and use it in GitHub Desktop.
Save Explosion-Scratch/154792ea7faf4254c9abdcd771e68868 to your computer and use it in GitHub Desktop.
Get Quizlet flashcards via API
async function quizlet(id){
let res = await fetch(`https://quizlet.com/webapi/3.4/studiable-item-documents?filters%5BstudiableContainerId%5D=${id}&filters%5BstudiableContainerType%5D=1&perPage=5&page=1`).then(res => res.json())
let currentLength = 5;
let token = res.responses[0].paging.token
let terms = res.responses[0].models.studiableItem;
let page = 2;
console.log({token, terms})
while (currentLength >= 5){
let res = await fetch(`https://quizlet.com/webapi/3.4/studiable-item-documents?filters%5BstudiableContainerId%5D=${id}&filters%5BstudiableContainerType%5D=1&perPage=5&page=${page++}&pagingToken=${token}`).then(res => res.json());
terms.push(...res.responses[0].models.studiableItem);
currentLength = res.responses[0].models.studiableItem.length;
token = res.responses[0].paging.token;
}
return terms;
}
quizlet("213648175").then(console.log);
@Whitelisted1
Copy link

Modified version:

async function getQuizletCards(id){
    let res = await fetch(`https://quizlet.com/webapi/3.4/studiable-item-documents?filters%5BstudiableContainerId%5D=${id}&filters%5BstudiableContainerType%5D=1&perPage=1000&page=1`).then(res => res.json());

    return [...res.responses[0].models.studiableItem];
}

This version doesn't repeatedly ask Quizlet for cards, simply asking Quizlet to return the maximum number of cards

@Explosion-Scratch
Copy link
Author

Nice, thanks

@rtrv
Copy link

rtrv commented Jul 22, 2024

Does it still work? I receive 403 error from Quizlet anyway

@Explosion-Scratch
Copy link
Author

Does it still work? I receive 403 error from Quizlet anyway

Try modifying it to set the cookie and check if there's an Authorization header then copy that if so. I'll debug later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment