Help

Automated script calling external API 403 Error

Topic Labels: Automations Integrations
372 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Tester1
4 - Data Explorer
4 - Data Explorer

Hi! I've been doing some scripting with the script extension, and managed to get it to a great working state when running manually in my base. I now want to put this in an automation sequence to trigger on a daily schedule. However, when running the script through automation, any API call I try to make is met with a 403 response. I've reached out to the company hosting the APIs I'm trying to call (Aha!), and they seem to believe the call doesn't even reach them (they can see my successful attempts from the manually triggered runs, but no blocked attempts), indicating something is being blocked by Airtable before the fetch call goes out.

For example, dumbing it down to a very simple call, the following works in the base when running manually (200 status response with expected JSON response), but fails when running automatically (403 status response, even gives me syntax error for 'unexpected end of JSON input'):

 

 

let apiToken = 'WORKING_KEY'

let response = await fetch(`https://workinglink.com/api/v1/working`, {
    method: 'GET',
    headers: {
        'Authorization': `Bearer ${apiToken}`,
        'Content-Type': 'application/json',
        'Accept': 'application/json',
    }
});

console.log('Response status:', response.status);
console.log('Response headers:', response.headers);
console.log('Response body:', await response.json());

 

 

Note, however, I'm able to call the below in the automated script:

 

let response = await fetch('https://worldtimeapi.org/api/timezone');

console.log('Response status:', response.status);
console.log('Response headers:', response.headers);
console.log('Response body:', await response.json());

 

Can anyone provide some guidance on what the blocker might be? Are there enterprise admin settings that could block me specifically from making certain API calls via automated scripts (I'm a user on an Enterprise plan), or am I missing something obvious with the automated script action and what the possibilities are?

2 Replies 2
Alexey_Gusev
13 - Mars
13 - Mars

Hi,

try a thing that helped me few times. I'm far rom understanding what happens and why it helped, but I think it worth a try.

const options={
    method:'GET',    
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    redirect: 'manual'
}

const hook='https://some_link'
const responce=await remoteFetchAsync(hook,options);
const result=(responce.ok)? await responce.text() : responce.statusText;
console.log(result)

 

just put the line

 redirect: 'manual'

after "method" or after "headers". don't forget to put comma.

Thanks for your response! Unfortunately, adding redirect: 'manual' does not appear to have any effect for me, still getting 403 from the automation script and 200 from running the same thing manually.