Managing webhooks
To automatically receive updates on a profile as soon as they occur, you must create a webhook. Each webhook event contains the profile information and the event details in the payload. If an event is enabled, the webhook will be triggered for all profiles in the system when it occurs.
You can register multiple webhook endpoints and enable as many events as you wish for each endpoint.
When an endpoint is registered for webhook, a secret token is generated for you to validate messages coming from the Amani system. This secret token will be passed as an HMAC signature in request headers.
1. Get the list of events
You can get the list of all available events and example payloads in the Amani system.
To enable/disable the events you must send {"enabled_events": ["event_name", ]}
during webhook endpoint create/update.
curl '<base_url>/api/v2/events' \
-H 'Authorization: Bearer <user_token>' \
2. Create a webhook endpoint
You should send the following informations during endpoint creation:
- Webhook URL
- Events your system needs to be notified for
- Custom headers you would like to receive for your webhooks
- Any metadata for your endpoint
curl --request POST '<base_url>/api/v2/webhook_endpoint' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <user_token>' \
--data '{
"url": "webhook_url",
"enabled_events": [],
"custom_headers": {},
"metadata": {}
}'
3. Get the secret token for your endpoint
The secret token must be stored securely on your system.
curl '<base_url>/api/v2/webhook_endpoint/<endpoint_id>/secret' \
-H 'Authorization: Bearer <user_token>'
4. Generate a new secret token for your endpoint
curl --request PATCH '<base_url>/api/v2/webhook_endpoint/<endpoint_id>/secret' \
-H 'Authorization: Bearer <user_token>' \
5. Update webhook
You can update any information regarding your endpoint.
curl --request PUT '<base_url>/api/v2/webhook_endpoint/<endpoint_id>' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <user_token>' \
--data '{
"url": "webhook_url",
"enabled_events": [],
"custom_headers": {},
"metadata": {}
}'
6. Get the logs for all triggered events for your endpoint
You can get detailed logs for all events:
curl '<base_url>/api/v2/webhook_endpoint/{{endpoint_id}}/logs \
-H 'Authorization: Bearer <user_token>'
7. Retry a failed event
You also have the option to retry triggering any failed event with the same payload.
curl --request POST '<base_url>/api/v2/webhook_endpoint/retry' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <user_token>' \
--data '{
"task_id": "task_id"
"body": "body"
"customer_id": "customer_id"
"webhook_id": "webhook_id"
"event_type": "event_type"
}'
8. Test an event
After registering your endpoint, you can test any of the events using dummy data:
curl --request POST '<base_url>/api/v2/webhook_endpoint/{{endpoint_id}}/test?event=event_name' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <user_token>'