Feb 10, 2021 09:59 PM
Hello,
Is there such thing as a fetch put? I am needing to do a put on an external api with the airtable scripting app. I was wondering what the best way to do it is? The external api is expecting a put method. I have successful used fetch for get and post but can’t seem to figure out the put. Thanks in advance!
Feb 11, 2021 06:24 AM
Hi @ALA_Staff, and welcome to the community!
Yes. Something like this…
let putURL = "https://...";
let putOptions = {
method: "PUT",
headers: {
'Accept' : 'application/json',
},
}
const putResults = await remoteFetchAsync(putURL, putOptions);
const jsonObject = await putResults.json();
output.inspect(jsonObject);
Feb 11, 2021 11:23 AM
Thanks for responding, Bill.
I’ve tried your suggestion. Here is my code.
let putUrl = "https://...";
let putOptions = (putBody) => {
return {
method: "PUT",
headers : {
"accountid":"...",
"applicationkey": "...",
"Accept": "application/json"
},
body:putBody
}
}
console.log("pre put");
let putResults = await remoteFetchAsync(putUrl, putOptions(JSON.stringify(prod)));
let jsonObject = await putResults.json();
output.inspect(jsonObject);
It runs up until the fetch call. the last thing that prints is “pre put”. I’ve tried this with postman and it works there. Just can’t seem to get it working with the script. Am I missing something? Thanks again
Feb 11, 2021 11:29 AM
Yes. But I do not know what it might be.
There are three scripting environments in Airtable - where [exactly] are you trying to run this script?
Feb 11, 2021 11:31 AM
I am using the Scripting App, downloaded from the Airtable apps Marketplace
Feb 11, 2021 11:33 AM
I would post the exact postman request header here so we can see the pattern that workers with your api.
Feb 11, 2021 11:39 AM
Feb 11, 2021 11:45 AM
here is the api documentation as well. DEAR Developer Portal · Apiary
From the docs, it says accountid, appkey, and content-type are the only required headers. it’s odd because i have the get and post calls working in the same script
Feb 11, 2021 12:38 PM
And yet, that is missing from your code - I would try adding that to see what happens.
Feb 11, 2021 12:48 PM
No luck, i’ve tried that in the past and just now. Still didn’t work. stops at the same spot