Webhooks can be created at an Organization or Workspace level
RESThooks
We have implemented a slightly extended version of webhook called “RESTful webhook”, or “resthook”. It allows you to programmatically manage webhook subscriptions like you would with any RESTful resources. For end-users, it means setting up a webhook subscription is a matter of clicking buttons, and no copy-pasting of URLs and cryptic tokens.Create a webhook subscription
There are 2 steps to creating a webhook:- Subscribe to an event
- The receiver confirms its intention to subscribe
Subscribe to an event
Request
URL: https://api.affinda.com/v3/resthook_subscriptions(endpoint details here) Method: POST Body:
The following events are deprecated in API V3 and should be used only by customers using API V2. API v3 customers should use the ‘document’ events above.
Response
Status code: 201 Body:Receiver confirms intention to subscribe
After the last step, we’ll POST to the receiver at https://your-receiver-domain.com/receive/ with aX-Hook-Secret header. The receiver should respond to this request with a 200 status code, and then activate the subscription using the X-Hook-Secret as below
Request
URL: /v3/resthook_subscriptions/activate Method: POST Headers:Receive a webhook notification
IP whitelisting
If your system requires IP whitelisting for incoming webhook notifications, use the following IP addresses based on your region: Australia:- 13.55.216.150
- 54.206.255.84
- 3.75.80.175
- 18.156.30.58
- 34.208.181.154
- 54.245.207.8
Verify webhook payload integrity
Enable webhook payload signing
To enable webhook payload signing, set up a resthook signature key for your account- Go to Affinda
- Click on the “Settings” tab of your Organization page
- In the section “Webhook Signature Key”, copy the generated key (or click “Regenerate” to get a new key)

Verify the webhook payload when you receive it
In the webhook notification that Affinda sends, there’s a header calledX-Hook-Signature of the following format: <timestamp>.<signature>.
To verify the webhook payload, sign the request body with the Signature Key you set up in the previous step using SHA256, then compare the resulting signature with the signature found in the X-Hook-Signature header. Only process the data if the signatures match!
Confirm payload timestamp is within a short range of current time to prevent replay attacks.
Example code