I'm working with some fairly basic scripts for two specific scenarios, one GET and one POST fetch (These are being run in the Edge developer console if that matters for anything it's the only option unfortunately).
For the GET, it works fine because there's no importance to which one gets processed first:
var arr = ['12345', '12534', '53435'];
arr.forEach((singleData) => {
const test = fetch(`https://COMPANY-LAN/apps/StdAction.do?actionId=100&workflowId=${singleData}`, {
"headers": {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "en-US,en;q=0.9",
"sec-ch-ua": "\" Not;A Brand\";v=\"99\", \"Microsoft Edge\";v=\"97\", \"Chromium\";v=\"97\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "cross-site",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1"
},
"referrer": "https://COMPANY-LAN/apps/StdAction.do",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": "null",
"method": "GET",
"mode": "cors",
"credentials": "include"
});
console.log(`Fetch for ${singleData} is complete`);
})
However, for the POST it's not working at all - I presume because it needs to complete the first item and then move on to the second one. As it's written, it runs through it but only the first item in the array gets processed with multiple POST's instead of once for each item in the array:
var arr = ['12345', '12534', '53435'];
arr.forEach((singleData) => {
const test = fetch("https://COMPANY-LAN/apps/StdAdction.do", {
"headers": {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "en-US,en;q=0.9",
"sec-ch-ua": "\" Not;A Brand\";v=\"99\", \"Microsoft Edge\";v=\"97\", \"Chromium\";v=\"97\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "cross-site",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1"
},
"referrer": `https://COMPANY-LAN/apps/StdAction.do?actionId=200&workflowId=${singleData}`,
"referrerPolicy": "strict-origin-when-cross-origin",
"body": "method=processApp&appRemarkString=Application+processed+by+script.",
"method": "POST",
"mode": "cors",
"credentials": "include"
});
console.log(`Fetch for ${singleData} is complete`);
})
I'm not all that familiar with async, would this be the better option? Or some other approach? Would appreciate any feedback. Also, as far as sequence goes - I'll be running the POST first for the entire array, and once that is complete and there's no issues, then I'll run the GET for the entire array (The real-world use will involve about 40-50 items in the array at a time).
Thanks.