Вы можете добавить item.id
к значению обещания, которое вы нажимаете
paymentIDArray.forEach(item => {
let p = rp({
uri: API + item.transactionID,
headers: {
"Content-Type": "application/json",
"Authorization": "Basic " + authCode
},
simple: false,
resolveWithFullResponse: false,
transform2xxOnly: false
}).promise();
promises.push(p.then(inspection => ({inspection, id: item.id})));
});
// each promise, instead of being just the result of `rp` is now {inspection: result of rp, id: item.id}
await Promise
.all(promises)
// vvvvv do you really need async? you are not awaiting in this code
.each(async ({inspection, id}) => {
if (inspection.isFulfilled()) {
// id is the required item.id
let result = JSON.parse(inspection.value());
} else {
logger.error(inspection);
logger.error("A promise in the array was rejected with", inspection.reason());
}
});