Show examples in:
Create a new webhook

Body Parameters

name  Required  string  Example: "Item type creation/update"

Unique name for the webhook

url  Required  string  Example: "https://www.example.com/webhook"

The URL to be called

headers  Required  object  Example: {"X-Foo":"Bar"}

Additional headers that will be sent

events  Required  Array<object>
custom_payload  Required  string, null  Example: "{ \"message\": \"{{event_type}} event triggered on {{entity_type}}!\", \"entity_id\": \"{{#entity}}{{id}}{{/entity}}\"] }"

A custom payload

http_basic_user  Required  string, null  Example: "user"

HTTP Basic Authorization username

http_basic_password  Required  string, null  Example: "password"

HTTP Basic Authorization password

enabled  Optional  boolean  Example: true

Whether the webhook is enabled and sending events or not

payload_api_version  Optional  string  Example: "3"

Specifies which API version to use when serializing entities in the webhook payload

nested_items_in_payload  Optional  boolean  Example: true

Whether the you want records present in the payload to show blocks expanded or not

auto_retry  Optional  boolean  Example: true

If enabled, the system will attempt to retry the call several times when the webhook operation fails due to timeouts or errors.

Returns

Returns a webhook resource object.

Examples

Example Basic example
import { buildClient } from '@datocms/cma-client-node';
async function run() {
const client = buildClient({ apiToken: '<YOUR_API_TOKEN>' });
const webhook = await client.webhooks.create({
name: 'Item type creation/update',
url: 'https://www.example.com/webhook',
headers: {
'X-Foo': 'Bar'
},
events: [
{
entity_type: 'item',
event_types: [
'update'
]
}
],
custom_payload: '{ \message\: \'{{event_type}} event triggered on {{entity_type}}!\', \entity_id\: \'{{#entity}}{{id}}{{/entity}}\'] }',
http_basic_user: 'user',
http_basic_password: 'password'
});
console.log(webhook);
}
run();