Choose your language:
    Create a new webhook
    Parameters
    name  string  Optional

    Unique name for the webhook

    url  string  Optional

    The URL to be called

    headers  object  Optional

    Additional headers that will be sent

    events  Array  Optional

    All the events you will be notified for

    customPayload  string, null  Optional

    A custom payload

    httpBasicUser  string, null  Optional

    HTTP Basic Authorization username

    httpBasicPassword  string, null  Optional

    HTTP Basic Authorization password

    enabled  boolean  Optional

    Whether the webhook is enabled and sending events or not

    payloadApiVersion  string  Optional

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

    nestedItemsInPayload  boolean  Optional

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

    Returns
    Returns a webhook object.

    Examples

    Example code:
    const SiteClient = require('datocms-client').SiteClient;
    const client = new SiteClient('YOUR-API-TOKEN');
    client.webhook.create({
    name: 'Item type creation/update',
    url: 'https://www.example.com/webhook',
    customPayload: '{ message: 'Successfully published record!' }',
    headers: {
    xFoo: 'Bar'
    },
    events: [
    {
    entityType: 'item_type',
    eventTypes: [
    'update',
    'create'
    ],
    filter: {
    entityType: 'item_type',
    entityIds: [
    '42',
    '43'
    ]
    }
    }
    ],
    httpBasicUser: 'user',
    httpBasicPassword: 'password',
    enabled: true,
    payloadApiVersion: '3',
    nestedItemsInPayload: true
    })
    .then((webhook) => {
    console.log(webhook);
    })
    .catch((error) => {
    console.error(error);
    });
    Returned output:
    > node example.js
    {
    "id": "312",
    "name": "Item type creation/update",
    "enabled": true,
    "url": "https://www.example.com/webhook",
    "customPayload": "{ message: 'Successfully published record!' }",
    "httpBasicUser": "user",
    "httpBasicPassword": "password",
    "headers": {
    "xFoo": "Bar"
    },
    "events": [
    {
    "entityType": "item_type",
    "eventTypes": [
    "update",
    "create"
    ],
    "filter": {
    "entityType": "item_type",
    "entityIds": [
    "42",
    "43"
    ]
    }
    }
    ],
    "payloadApiVersion": "3",
    "nestedItemsInPayload": true
    }