Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Feb 24, 2021 08:08 AM
I’m calling an Apps Script which works as intended in the browser. However when using automation I get the error. I have read that this is to do with google redirecting the url.
I don’t need to receive anything back from the script as everything is handled there.
Are there any other ways around this? I could put it in a button but then it wouldn’t be automated. Also if possible I would like to avoid using another intermediary service.
Solved! Go to Solution.
Feb 26, 2021 07:28 AM
I was about to respond to this message when I saw your recent messages.
I had intimated earlier that it was likely something else that was causing you to believe your action script was inadequate. It wasn’t - it was something in your web app deployment or the code, or both, right?
This is bad advice. The entire point of this thread is to make it work without using another service. You caved to the Goldbergian buffoonery unless there was never a clear benefit to calling Apps Script directly in the first place. :winking_face:
Share with us - what happens after you call the Integromat webhook?
BTW - while Airtable is unable to follow redirects, a well-designed webhook in Google Apps Script is perfectly capable of receiving requests and performing complex operations in a call-back process. This function works flawlessly - made almost 20,000 calls last month with not a single failure. Note how a response 302 is reimagined as a 200. :winking_face:
//
// call the mail service
//
async function callOneMail(task, recordID)
{
const url = "https://script.google.com/macros/s/.../exec?token=12345&task=" + task + "&id=" + recordID;
let getResponse;
let getOptions = {
method: "post",
headers: {
'Accept' : 'application/json',
}
}
try {
let getResults = await fetch(url, getOptions);
getResponse = await getResults.json();
} catch (e) {
getResponse = {
"result" : "200OK",
"elapsedTime" : 0.0
}
}
return(getResponse);
}
Feb 24, 2021 09:10 AM
Just script the process to gracefully fail with a try … catch.
try {
// call the API here...
} catch (e) {
// do nothing...
}
Feb 24, 2021 09:35 AM
Thanks Bill, I did try this approach. While no error shows in Airtables scripting editor. The request doesn’t get through to Apps Script.
Feb 24, 2021 09:50 AM
That suggests another issue - when you test the action, does it succeed?
Feb 25, 2021 12:17 AM
let inputConfig = input.config();
let id = inputConfig.RecordID;
let scriptURL = “https://script.google.com/macros/s//exec?”;
let urlRequest = (scriptURL + id);
console.log(scriptURL + id);
try{
let response = await fetch(urlRequest, {method : “Get”, redirect : “follow”});
console.log(await response.json());
} catch(e){
//nothing
}
Here is the code maybe I’m doing something stupid.
From my testing so far.
Using try then testing the script completes successfully but no data is received to activate the apps script
Adding redirect : “follow” changes the error to: TypeError: Requests that follow redirects are not supported currently
Swapping out the apps script url for ‘https://api.github.com/orgs/Airtable’ everything functions as expected and a normal response is received.
Feb 26, 2021 05:54 AM
Just an update for anyone else with the issue. That will hopefully save some headaches.
Following redirects is not currently possible. See Airtable redirects
As per advice from Airtable I used integromat as an intermediary service.
The process is pretty simple.
Create a custom webhook in integromat
Take the url from the webhook and use it in your Airtable automation script, pass any variables at the end of the url.
In integromat set the custom webhook to listen mode. Then run/test your script in airtable and integromat should automatically detect your variables.
Add a http module in integromat and connect it to your custom webhook. You can use the variables in in the http module to send to Apps Script web app and you’re done.
Bonus gotcha… don’t be a dope like me and make sure you have your apps script web app deployed with the settings
Otherwise the the request will bump into the sign into google authentication screen.
.
Feb 26, 2021 07:28 AM
I was about to respond to this message when I saw your recent messages.
I had intimated earlier that it was likely something else that was causing you to believe your action script was inadequate. It wasn’t - it was something in your web app deployment or the code, or both, right?
This is bad advice. The entire point of this thread is to make it work without using another service. You caved to the Goldbergian buffoonery unless there was never a clear benefit to calling Apps Script directly in the first place. :winking_face:
Share with us - what happens after you call the Integromat webhook?
BTW - while Airtable is unable to follow redirects, a well-designed webhook in Google Apps Script is perfectly capable of receiving requests and performing complex operations in a call-back process. This function works flawlessly - made almost 20,000 calls last month with not a single failure. Note how a response 302 is reimagined as a 200. :winking_face:
//
// call the mail service
//
async function callOneMail(task, recordID)
{
const url = "https://script.google.com/macros/s/.../exec?token=12345&task=" + task + "&id=" + recordID;
let getResponse;
let getOptions = {
method: "post",
headers: {
'Accept' : 'application/json',
}
}
try {
let getResults = await fetch(url, getOptions);
getResponse = await getResults.json();
} catch (e) {
getResponse = {
"result" : "200OK",
"elapsedTime" : 0.0
}
}
return(getResponse);
}
Feb 26, 2021 08:29 AM
Hi Bill, Yes there were two issues,
I solved the permissions issue on the script last(after setting up integromat).
So I just went back to my code posted above. Ran it again with the apps script URL…fail TypeError: Requests that follow redirects are not supported currently
Then I took out the redirect : “follow” and it succeeded.
You were correct  :slightly_smiling_face:
Feb 26, 2021 08:36 AM
Yep - unfortunately, you were dealing with three different issues at once.
Dec 10, 2022 02:39 PM
Thomas, brillant solution, I'm trying it. Easy to go till HTTP request, all parameters are properly passed by webhook, HTTP works (see result) but GAS script doesn't give any result..
So I tried HTTP module alone (see img) but something is wrong in the module configuration because the called Google App Script (which is simply renaming a file in GoogleDrive) is working well if initiated from the browser, is not from Make Any suggestion? Tks in advance.