Help

Upcoming database upgrades. Airtable functionality will be reduced for ~15 minutes at 06:00 UTC on Feb. 4 / 10:00 pm PT on Feb. 3. Learn more here

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

Topic Labels: Automations
199 1
cancel
Showing results for 
Search instead for 
Did you mean: 

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));

1 Reply 1

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.