Jun 15, 2023 12:11 PM
I am trying to create an automation and I am trying to setup a POST webhook using the documentation at: https://airtable.com/developers/web/api/create-a-webhook
But every time, I get a syntax error in the first line. I have ensured all the correct data was entered, like my BaseId, Token, and Webhook URL.
I am stuck! Any guidance would be incredible 🙌
Jun 15, 2023 12:43 PM
Hey @leifika!
curl is a command-line tool, and cannot be used within the Airtable scripting environment to send HTTP requests.
To send an HTTP request from the Airtable scripting environment, the Fetch API is enabled, giving you access to the global fetch() method.
There are a couple ways to format and build the request. Here's an example of just one of the ways you could format the request you displayed in your screenshot:
let requestBody = {
notifications: "THE_WEBHOOK_URL",
specification: {
options: {
filters: {
dataTypes: [
"tableData"
],
recordChangeScope: "tbltp8DGLhqbUmjK1"
}
}
}
};
let endpoint = "https://api.airtable.com/v0/MY_AIRTABLE_BASE/webhooks";
let options = {
method: "POST",
headers: {
"Authorization": `Bearer MY_AIRTABLE_TOKEN`,
"Content-Type": "application/json"
},
body: JSON.stringify(requestBody)
};
await fetch(endpoint, options)
.then(response => {
console.log(`Response:`, response);
return response.json();
})
.then(data => console.log(`Response Data:`, data))
Naturally, if you copy and paste this request straight into Airtable and attempt to run the script, it will almost certainly fail because the requestBody.specification.options.filters.recordChangeScope value is probably not a table id that exists anymore.
Nonetheless, this is something along the lines of what a request could look like.