so I've seen a few post about pagination with Axios, but what I've seen is primarily discussion around front-end. Effectively what I'm trying to do is use Axios to do a GET request, save my results and move on to the next pagingated request.
End goal is to take all requests and save them into a large .txt file.
Here is my problem so far. I have been able to make my first request and add the data result to a variable. However, the next call won't take the varaiable for the continuation parameter, because of the scope. I tried nesting it (see below) but it hasn't worked. I'm relatively new to Node.js and still don't fully understand promises but I'm willing to learn. If there is an answer to this somewhere already, please let me know. Otherwise, any help would be greatly appreciated.
Thank you
const axios = require('axios');
const eventBriteToken = '1234'
// Make a request for a user with a given ID
axios.get('https://www.eventbriteapi.com/v3/organizations/12345/attendees', {
params: {
token: eventBriteToken,
}
})
.then(function (response) {
// handle success
console.log(response.data.pagination.page_number)
const continuationID = response.data.pagination.continuation
//console.log(response)
axios.get('https://www.eventbriteapi.com/v3/organizations/12345/attendees', {
params: {
token: eventBriteToken,
continuation: continuationID
}
})
console.log(response.data.pagination.page_number)
})
.catch(function (error) {
// handle error
//console.log(error);
})
.then(function () {
// always executed
});