Mar 16, 2020 07:32 PM
Hey,
I’m a newbie with JavaScript so this might be obvious …
I need a delay(ms) method to slow down the script after 5 API calls (limit 5/min.). Problem is all the JavaScript help on the intertube points to the setTimeout() method of the Window object. But it appears that Window is not instantiated inside the Airtable code block, therefore, no setTimeout() method. What’s a good workaround for this?
What might I be missing - other methods?
Thanks
David
Mar 27, 2020 12:03 PM
Thanks guys!
Here it is:
curl --header “api-key: [apikeytxt]” -X GET "https://api-hazards.atcouncil.org/public/v1/wind.json?lat=[lat variable]&lng=[long variable]
Mar 27, 2020 01:47 PM
Something like:
let url = '"https://api-hazards.atcouncil.org/public/v1/wind.json?lat=[lat variable]&lng=[long variable]';
let getOptions = {
method: "get",
headers: {
'api-key' : 'apiKeyHere',
'Accept' : 'application/json',
}
}
let postResults = await fetch(url, getOptions);
Mar 27, 2020 08:54 PM
That worked! Thank you, sir!
With how much our business uses random APIs like this, I plan on sharing this and another script we recently created in the forum once they’re up and running.
Apr 12, 2020 01:29 PM
This strategy still doesn’t seem to work on my end. Here’s a complete example to demonstrate. Am I doing something wrong on my end?
function timeout(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function test() {
output.text("foo");
await timeout(300);
output.text("bar");
}
test();
Expected: “foo” prints, then “bar” 300ms later.
Actual: “foo” prints, “bar” never does.
Apr 12, 2020 01:46 PM
You need to await the test function when you call it.
await test();
Jul 25, 2020 03:56 PM
Thank you very much @openside,
I was just needing a DELAY and you’ve helped very much !
As I read the all thread coming from this one:
I would add that
window is globalThis here in the Script-Block.
Thank you and good night (GMT),
olπ
Dec 27, 2020 07:36 AM
It is not working on my script. Do you guys have solution already for this?
Dec 27, 2020 10:18 AM
Welcome to the Airtable community!
It looks like you are using an automation script. The scripts which have been able to use setTimeout have been scripts run in Scripting app. There are a few differences between running a script as an automation and running a script in Scripting app. The ability to use setTimeout appears to be one of these differences.
Dec 27, 2020 08:27 PM
Do you know any alternative to put delay in automation script?
Dec 27, 2020 09:38 PM
Why do you need a delay in your automation script? That might influence the approach. Two common approaches are reworking the trigger, or splitting the automation into two automations.