Help

Re: Create a webhook on update of records in the Contact table of my CRM base

3803 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Kosta_Kondraten
7 - App Architect
7 - App Architect

I am attempting to setup a webhook to ping a URL on my app any time a record in my Contact table is updated. Upon research I have found the following URL:
https://support.airtable.com/docs/airtable-webhooks-api-overview
specifically this section:
https://airtable.com/developers/web/api/create-a-webhook

My challenge is in configuring the request, specifically confusion about the URL which is:
https://api.airtable.com/v0/bases/{baseId}/webhooks

And wondering if I could narrow that to a table and also

what the 'recordChangeScope' means and how to configure it for my goal of Contact webhook pings:

{
"notificationUrl": "https://foo.com/receive-ping",
"specification": {
"options": {
"filters": {
"dataTypes": [
"tableData"
],
"recordChangeScope": "tbltp8DGLhqbUmjK1"
}
}
}

 

2 Replies 2
Ben_Young1
11 - Venus
11 - Venus

Hey @Kosta_Kondraten

The documentation (that you already found) is actually quite solid on explaining how the Webhooks API works and how you can interact with it.
Not exactly sure what your confusion is regarding the webhook creation API endpoint, but all you need to do is insert your base id. Something like this:
"https://api.airtable.com/v0/bases/apppr7keotkS6ls4r/webhooks"

The specification property is an object containing the options object. The options object utilizes Airtable's Webhooks specification data model. This is where you can define the behavior for the webhook notifications. If you haven't already looked at it, here's Airtable's data model for how to build the options object.

If you want to isolate the behavior to only a specific table or view, you can pass recordChangeScope with the id of the desired table or view like you posted in the example snippet from the documentation.

So, if I want to create a webhook to a base with the id of "apppr7keotkS6ls4r" and only want webhooks for a table with the id of "tbliqbuc4ZxJPC352", my request would look like this:

 

 

curl -X POST "https://api.airtable.com/v0/bases/apppr7keotkS6ls4r}/webhooks"\
-H "authorization: Bearer your_token"\
-H "content-type: application/json"\
-d '{
    "specification": {
      "options": {
        "filters": {
          "dataTypes": ["tableData"],
          "recordChangeScope": "tbliqbuc4ZxJPC352"
        }
      }
    }
  }'

 

 

or...

 

 

const createWebhookEndpoint = "https://api.airtable.com/v0/bases/apppr7kmTukS6ls4r/webhooks";
const requestBody = {
	specification: {
		options: {
			filters: {
				dataTypes: ["tableData"],
				recordChangeScope: "tbltp8DGLhqbUmjK1"
			}
		}
	}
};

const requestOptions = {
	method: "POST",
	headers: {
		"authorization": "Bearer your_token",
		"content-type": "application/json"
	},
	body: JSON.stringify(requestBody)
};

 

 

When successful, it will return a 200 status and the information about the newly created webhook.

Hi Ben,

Thank you for your quick response and providing the example - you're right it's pretty straightforward.

I have ran the URL you suggested to:

https://api.airtable.com/v0/bases/myBaseID/webhooks

And received the following response:

{
"error": {
"type": "INVALID_PERMISSIONS",
"message": "You are not permitted to perform this operation"
}
}

Any input or ideas for the cause of this and how to troubleshoot would be much appreciated.

Thank you!