I am nesting an Axios call in another in order to get the list of IDs from my first call and then loop through and for each ID get the status from a 2nd API call. It will only return the first status when I log the array, versus showing the full array.
I believe the issue may be in the promise chain... or if this is not waiting for the promises to complete before outputting the final array.
var responsearray = []
axios.get('https://myapi.net/api/role/allroles?pageSize=1000').then(function (response) {
for(var i = 0; i < response.data.roles.length; i++)
{
var entry = response.data.roles[i];
var entryid = entry.id;
return axios.get('https://myapi.net/api/role/score/' + entryid).then(function (response2) {
// Nested call per role to push to array
responsearray.push(response2.status)
});
}
}).catch(function (error) {
// handle error
console.log(error);
}).then(function () {
// always executed
// Return Array
console.log(responsearray);
});