Set up a webhook
Set up a webhook when another system needs to hear about changes in Drum as they happen, instead of polling the API.
Before you begin
You need:
- The
manage_webhookspermission - An endpoint on your server that accepts
POSTrequests over HTTPS, at a public address, with a valid certificate
1. Create the subscription
- Open your user menu and select Profile.
- Select Webhooks in the settings menu.
- Select Create Webhook.
- Enter a Name, such as “Accounting sync”.
- In Url, enter your endpoint’s address.
- Under Subscribed events, select the events you want. Events says when each one fires.
- Select Create Webhook.
Drum opens the subscription’s page. The status is Active.
To create a subscription from code instead, see Manage subscriptions with the API.
2. Store the secret
On the subscription’s page, select the copy button next to Secret. Store it with your endpoint’s configuration, in the same place you keep other credentials. Your endpoint uses it to check that each request came from Drum.
Each subscription has its own secret. If you send two subscriptions to one endpoint, look up the secret by the URL or a path segment you put in each subscription’s URL.
3. Verify the signature
For every request, rebuild the signature from the raw body and compare it with the X-Webhook-Signature header. Reject the request if they differ, or if X-Webhook-Timestamp is more than a few minutes old.
Code for Ruby, Python and Node.js is in Verify webhook signatures.
4. Respond quickly
- Verify the signature.
- Store the raw body, or put it on a queue.
- Return
200straight away, then do the work in the background.
Drum waits at most 30 seconds. Anything other than a 2xx response counts as a failed attempt. A 5xx, 408, 429 or timeout is tried again, but any other 4xx fails the delivery at once. See Delivery and retries.
5. Handle repeats and ordering
- Events can arrive out of order. For each record, keep the event with the latest
data.attributes.updated_at, and ignore an older one. - Several quick changes to one record can arrive as a single
.updatedevent. - The same event can arrive more than once. To ignore repeats, record
event,data.type,data.idanddata.attributes.updated_atfor each event you process, and skip one you have seen.
6. Check the first deliveries
Make a change in Drum that fires one of your events. On the subscription’s page, Last triggered at shows the time of the last successful delivery, and Delivery Statistics shows the count and any consecutive failures.
To see each delivery’s request and your endpoint’s response, read the deliveries through the API. See Fix failed deliveries.
Change, pause or delete the subscription
On the subscription’s page:
- Select Edit to change its name, URL or events.
- Select Pause to stop deliveries while keeping the settings, and Resume to start them again. Events that happen while it is paused are never sent.
- Select Delete to remove it. Deliveries stop at once.
The secret cannot be changed. To use a new secret, create a new subscription, move your endpoint to its secret, then delete the old one.