Show examples in:
Javascript HTTP
Endpoint info
Available examples
Content Management API > Webhook

Create a new webhook

Body parameters

type string Required

Must be exactly "webhook".

attributes.name string Required

Unique name for the webhook

Example: "Item type creation/update"
attributes.url string Required

The URL to be called

Example: "https://www.example.com/webhook"
attributes.headers object Required

Additional headers that will be sent

Example: { "X-Foo": "Bar" }
attributes.events Required
Type: Array<object>
entity_type enum Required

The subject of webhook triggering

Example: "item"
item_type Optional
item Optional
upload Optional
build_trigger Optional
environment Optional
maintenance_mode Optional
sso_user Optional
cda_cache_tags Optional
event_types Required
Type: Array<string>
filters Optional
Type: Array<object>, null
entity_type enum Required
item_type Optional
item Optional
build_trigger Optional
environment Optional
environment_type Optional
entity_ids Required
Type: Array<string>
attributes.custom_payload string, null Required

A custom payload

Example: '{ "message": "{{event_type}} event triggered on {{entity_type}}!", "entity_id": "{{#entity}}{{id}}{{/entity}}"] }'
attributes.http_basic_user string, null Required

HTTP Basic Authorization username

Example: "user"
attributes.http_basic_password string, null Required

HTTP Basic Authorization password. It is null when the webhook has no basic auth, or when the credentials you are using cannot manage the webhooks of the project.

Example: "password"
attributes.enabled boolean Optional

Whether the webhook is enabled and sending events or not

attributes.payload_api_version string Optional

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

Example: "3"
attributes.nested_items_in_payload boolean Optional

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

attributes.auto_retry boolean Optional

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 resource object of type webhook.

Examples

POST https://site-api.datocms.com/webhooks HTTP/1.1
Authorization: Bearer YOUR-API-TOKEN
Accept: application/json
X-Api-Version: 3
Content-Type: application/vnd.api+json
{
"data": {
"type": "webhook",
"attributes": {
"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"
}
}
}
Terminal window
curl -g 'https://site-api.datocms.com/webhooks' \
-X POST \
-H "Authorization: Bearer YOUR-API-TOKEN" \
-H "Accept: application/json" \
-H "X-Api-Version: 3" \
-H "Content-Type: application/vnd.api+json" \
--data-binary '{"data":{"type":"webhook","attributes":{"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"}}}'
await fetch("https://site-api.datocms.com/webhooks", {
method: "POST",
headers: {
Authorization: "Bearer YOUR-API-TOKEN",
Accept: "application/json",
"X-Api-Version": "3",
"Content-Type": "application/vnd.api+json",
},
body: JSON.stringify({
data: {
type: "webhook",
attributes: {
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",
},
},
}),
});
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: cache-control: max-age=0, private, must-revalidate
X-RateLimit-Limit: 30
X-RateLimit-Remaining: 28
{
"data": {
"type": "webhook",
"id": "312",
"attributes": {
"name": "Item type creation/update",
"url": "https://www.example.com/webhook",
"enabled": true,
"headers": {
"X-Foo": "Bar"
},
"events": [
{
"entity_type": "item",
"event_types": [
"update"
]
}
],
"http_basic_user": "user",
"http_basic_password": "password",
"custom_payload": "{ \"message\": \"{{event_type}} event triggered on {{entity_type}}!\", \"entity_id\": \"{{#entity}}{{id}}{{/entity}}\"] }",
"payload_api_version": "3",
"nested_items_in_payload": true,
"auto_retry": true
}
}
}