Fetch - TypeError: Response status was 302 'Moved Temporarily' but redirect mode was set to 'error'

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.

Just script the process to gracefully fail with a try … catch.

try {
  // call the API here...
} catch (e) {
  // do nothing...
}
1 Like

Thanks Bill, I did try this approach. While no error shows in Airtables scripting editor. The request doesn’t get through to Apps Script.

That suggests another issue - when you test the action, does it succeed?

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.

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.

  1. Create a custom webhook in integromat

  2. Take the url from the webhook and use it in your Airtable automation script, pass any variables at the end of the url.

  3. In integromat set the custom webhook to listen mode. Then run/test your script in airtable and integromat should automatically detect your variables.

  4. 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

  • “Execute the app as:” : Me
  • “Who has access to the app:”: Anyone, even anonymous

Otherwise the the request will bump into the sign into google authentication screen.
.

1 Like

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. :wink:

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. :wink:

//
// 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);
}
1 Like

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:

1 Like

Yep - unfortunately, you were dealing with three different issues at once.

This topic was solved and automatically closed 3 days after the last reply. New replies are no longer allowed.