I have a NIH API that can call only 50 pages at a time. The code below works for the first page of 50 items.
loadNIH() {
let offset = 0;
axios({
method: "GET",
url:
"https://api.federalreporter.nih.gov/v1/projects/search?query=orgName:Medical University of South Carolina$fy:2016$&offset=" + offset +"&limit=50"
})
.then(res => {
this.NIHData = res.data.items;
})
.catch(function(error) {
console.log(error);
});
},
I need to loop all of the pages until I get all of the data. Each time the offset needs to increase by the number of pages received (requested 50) 9 pages in this call. I need it to ADD data to the array of this.NIHData. I got one working so I need some help creating the loop.
Thanks in advance
offsetout of your function, useoffset += 50inside the function, and callloadNIH()from inside the success path? (Until a condition is met)