I need to fetch some results from an endpoint and the way it is structured, the response tells me what endpoint to use next for the next set of results (current limit of 1k rows per request), until all results have been obtained. I then need to stitch the data back together.
I can relatively easily fetch one set of results using the following code, but struggle to understand how I can wait for the results in order to fetch the next set, unless I nest it, and I don't want to do that as I don't know how many sets of results I need to fetch upfront.
var headers = {
'Content-type': 'application/json',
'X-DBX-AUTH-TOKEN': 'yyy@zzz.com/6573846tf9334e'
};
var options_results = {
method: 'GET',
headers: headers,
};
var url = 'https://endpoint/execute/{uuid}/0';
options_results.url = url;
function fetchResults(error, response, body) {
console.log(body);
var next_uid = JSON.parse(body.uuid);
}
request(options_results, fetchResults);
I have read up on promises etc, but am still struggling how to apply that here. Any help would be really appreciated!