I have a series of request that I would like to call in a for-loop.
The only thing I am changing in the endpoint is an index parameter. This index parameter should be the same as the index of for-loop(0-100).
However the promise return values are all the same response from one of the endpoints. (i.e. all the return values are what I would expect from ${someEndPoint}?index=61).
someIndex = 100
var promises = [];
for (var i = 0; i < someIndex; i++){
var options = {
method: 'GET',
uri: `${someEndPoint}?index=${i}`,
json: true
}
promises.push(request(options))
}
Promise.all(promises).then(function(values){
console.log(values) // returns array of 100 of the same responses.
}).catch(e => {
console.log(e)
});
P.S. I'm using a node.js server, and it shows that my server has made all 100 of the correct GET calls, but the values object has only been populated with one specific request response multiple times.
[{ index: 70, data: '...' },
{ index: 70, data: '...' },
...
{ index: 70, data: '...' },
{ index: 70, data: '...'} ]
How am I suppose to get the correct responses?