Dec 06, 2021 09:08 AM
Hi,
I’m currently in the process of trying to perform an automated update of a table record based on the trigger type “When Webhook received” (still in alpha dev phase).
It indicates sending a webhook request to an ‘example’ webhook address in order to indicate ID references.
I have placed the example webhook address into a script app in the base that is intended to trigger the update automation via webhook. I have also included two input variables in the webhook call.
The intent in doing this is to have the script call the webhook to trigger update automation and use the input variables to a) identify the correct record to update and b) provide the updated value to the intended field to update.
The result is the error in the screenshot below.
This raises the obvious two-part question: Why is the console message indicating that the URL is not found and the automation test failing as a result?
Thoughts anyone?
Am I overcomplicating this endeavor to start with?
Thanks in advance!
(Yes, I haven’t been doing Airtable scripting that long)
Dec 07, 2021 05:27 AM
Welcome to the Airtable community!
You need to call the webhook using POST, not the default GET. You also need to include your input variables in the POST body, not as URL parameters.
Dec 07, 2021 09:57 AM
Hello and thanks for your reply.
Totally makes sense - got stuck on variables and overlooked the method.
I’m having a little trouble finding proper documentation and examples of specifying the POST method and data within a fetch call (inside an AT script app).
I would expect it to be approximately as simple as:
let confirmAll = await fetch({
method: POST,
data: {
classID: config.classID,
walletCount: config.walletCount
}
});
Yet, this doesn’t seem to be the case. Still looking for fetch references (currently copying a community example base), but would appreciate any further syntax insights you might have.
Thanks again!
Joe
Dec 07, 2021 10:16 AM
Are you getting a new different error?
Unless you have a variable named POST
with the proper value, you need to put it in quotes.
method: "POST",
Dec 07, 2021 10:48 AM
Yes, after doing a few variations and bringing it down to the most basic request structure, it’s sending a 400 status (bad request), versus 404 - Not Found. See below
Dec 07, 2021 10:50 AM
Pasted the wrong reply capture - refer to this one instead
Dec 07, 2021 11:02 AM
You need to have your post body in JSON format and have a header that says your content is in JSON format.
You also need to convert the response into readable text.
Here is more documentation about fetch.
Dec 14, 2021 04:17 PM
This is what you should do:
if you’re passing data as JSON, you should call:
const url = "https://hooks.airtable.com/workflows/v1/genericWebhook/urlxyz";
let options = {
method: "POST",
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({test: false})
}
const res = await fetch(url, options);
And if you want to pass data as parameters:
const url = "https://hooks.airtable.com/workflows/v1/genericWebhook/urlxyz?data=abc";
let options = {
method: "POST",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
}
const res = await fetch(url, options);