Help

syntax error POST webhook

Topic Labels: Automations
817 1
cancel
Showing results for 
Search instead for 
Did you mean: 
leifika
4 - Data Explorer
4 - Data Explorer

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 🙌

 

Screenshot 2023-06-15 at 21.05.47.png

1 Reply 1

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.