Webhooks
Webhooks are push notifications when a work is created, updated or deleted.
Last updated
Webhooks are push notifications when a work is created, updated or deleted.
Last updated
You can add a webhook URL in your accounts page on Laws.Africa at https://edit.laws.africa/accounts/profile/webhooks.
When a Work Expression is created, updated or deleted, Laws.Africa will send a POST request to the webhook URL with details of the action in JSON in the body of the request.
Under Add a new webhook fill in the URL field with your webhook URL.
Click Add webhook
Click the Delete button alongside the webhook you wish to delete.
The body of a webhook invocation request contains the following information:
A webhook invocation should be treated as an indication that the work has been changed or deleted. It should do minimal work so that it can respond within the 10 second timeout. A common approach is to trigger an asynchronous (background) task to fetch/refresh the data for all expressions of the work, and return a 200-success response.
Laws.Africa expects the webhook endpoint to return a 200-level response code within 10 seconds. A response that takes longer than that is considered a failure.
Laws.Africa will retry a failed (non-200 response) webhook invocation up to 10 times. Laws.Africa will initially retry after just a few seconds. If more attempts fail, it will use exponential backoff to delay retrying longer and longer (up to a few hours between attempts).
It is possible for a work to be updated rapidly in quick succession. Laws.Africa will group multiple updates to the same work within a short period (30 seconds) into a single invocation. This avoids overloading the webhook target with repeated invocations in quick succession.
Because a webhook invocation can be retried, it is important that your webhook endpoint can safely process a duplicate invocation. Laws.Africa cannot guarantee exactly-once delivery of a webhook invocation.
In rare cases a work may be deleted and then re-created a few minutes later. The order of the webhook invocations is not guaranteed. This means that you may receive the “deleted” webhook invocation after the “created” invocation (this is the joy of distributed systems across the Internet!).
Therefore, rather than immediately deleting a work when getting a “deleted” webhook, first call the Laws.Africa API to see if that work still exists. If the API returns a 404, then it is safe to delete that work. If the work does exist, then consider your copy out of date and treat the invocation as an “updated” invocation.