Help

Re: Script with fetch is failing

3400 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Jonathan_Frank
5 - Automation Enthusiast
5 - Automation Enthusiast

I’m trying to use scripting to call APITemplate.io to create a PDF file from some data. The fetch is failing. It works from Postman so I know the call is valid. I’ve taken the exact code from the Airtable script and run it locally in node.js - with the addition of npm install node-fetch and some top-level async function syntax so I can await, and that works fine too. So there’s something about calling the code from within an Airtable script that makes it return with a 303 error. Unfortunately I can’t find any logging at apitemplate.io to help me. Anyone have any ideas as to what I can look at?

let url = "https://api.apitemplate.io/v1/create?template_id=<id>";
let headers = {
    "X-API-KEY": "<apikey>",
    "Content-Type": "application/json"
};

let body = {content: "data"};

let response = await fetch(url, {
    method: "POST",
    headers: headers,
    body: JSON.stringify(body)
});

let result = await response.json();
console.log(`download result from : ${result}`);
5 Replies 5

You need to be more specific if you want to get some help. Why is it failing? Screenshot maybe?

Yes, first switch to Autocode; it has a fully-baked logging system.

Then, read the Airtable SDK docs concerning remoteFetchAsync.

Well, as I said it’s failing with a 303 error. There’s not much more to it than that:

ERROR
TypeError: Response status was 303 'See Other' but redirect mode was set to 'error'
    at main on line 26

Autocode is new to me and looks interesting. Trouble is, I’ve got this script working for other APIs - it’s this one to apitemplate.io that’s failing, and I wanted to see if anyone had already done this successfully.

Yes, I’ve read the docs relating to remoteFetchAsync but my understanding was that that was for apps. This is an automation. I’m new to Airtable … have I misunderstood the distinction here??

Um, no. I was not informed that your script was an action script.

Actually, the trouble is with apitemplate.io - it doesn’t allow you insights to easily debug the issue when using their platform. Autocode does. And since you have it working with other APIs, if you want to stay with apitemplate.io, this is really a support question for them, right?

Turns out the issue was that apitemplate.io requires redirect in the http fetch, which airtable doesn’t support (and which I should have realised from the error message). I’m going via an AWS lambda middle layer - for various reasons this isn’t as overkill as it sounds and will work out fine.

Wow, this feels like discovering Glitch all over again. I probably should have been aware of such a powerful resource already but I’m just glad I am now, thanks for the link.