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!
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
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
Yes. But I do not know what it might be.
There are three scripting environments in Airtable - where eexactly] are you trying to run this script?
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?
I am using the Scripting App, downloaded from the Airtable apps Marketplace
I am using the Scripting App, downloaded from the Airtable apps Marketplace
I would post the exact postman request header here so we can see the pattern that workers with your api.
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
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
And yet, that is missing from your code - I would try adding that to see what happens.
And yet, that is missing from your code - I would try adding that to see what happens.
No luck, i’ve tried that in the past and just now. Still didn’t work. stops at the same spot
No luck, i’ve tried that in the past and just now. Still didn’t work. stops at the same spot
Without seeing the actual code, this could take many days to debug.
Without seeing the actual code, this could take many days to debug.
I got it working. I had the fetch call in an async function. guess it didn’t like that. thanks for your help!
Without seeing the actual code, this could take many days to debug.
let putUrl = "https://inventory.dearsystems.com/ExternalApi/v2/product";
let checkProductSupplierList = async (prod) => {
// get supplierID to add to product suppliers list
let linkedID = suppliers["linkedRecordIds"][0];
let supplier = supplierRecords.getRecord(linkedID);
let supplierID = supplier.getCellValue("SupplierID")[0];
if (prod["Suppliers"].length === 0) {
prod["Suppliers"] = [{ "SupplierID": supplierID, "DropShip": true }];
prod["DropShipMode"] = "Optional Drop Ship";
let putResults = await remoteFetchAsync(putUrl, options("put", JSON.stringify(prod)));
let putObject = await putResults.json();
console.log("put response", putObject)
}
for (let product of lines) {
if (product["SKU"] === productSku) {
let prod = await getProduct(product["ProductID"]);
prod = prod['Products'][0];
checkProductSupplierList(prod)
}
product["DropShip"] = true;
break;
}
}
What worked was this…
let checkProductSupplierList = (prod) => {
let linkedID = suppliersr"linkedRecordIds"]"0];
let supplier = supplierRecords.getRecord(linkedID);
let supplierID = supplier.getCellValue("SupplierID")"0];