I wrote the following code in the automation script and it seems to give me an error which should not happen as per JS docs

This is the code, all variables exist in this but it says can only use await on async functions:

fetch(“https://api.onfinance.in/insights”, requestOptions)
.then(response => response.text())
.then((result) => {
for(let j=0; j<checkedDataIDS.length; j++){
await table.deleteRecordAsync(checkedDataIDS[j]);
console.log("Processed Insights: ", checkedDataIDS);
.catch(error => console.log(‘error’, error));

That’s because you are only allowed to use await in async functions. You use await when you delete the record in the anonymous function in your second “then”.

It is probably easier to understand if you use a different syntax.

async function doStuff() {
const response = await fetch(“https://api.onfinance.in/insights”, requestOptions)
const result = await response.text()

for(let j=0; j<checkedDataIDS.length; j++) {
await table.deleteRecordAsync(checkedDataIDS[j]);

You would also be better off submitting the delete requests in batches, instead of one at a time.