Laws.Africa Developer Guide
  • Laws.Africa Developer Guide
  • Get Started
    • Introduction
    • Quick start
    • Works and expressions
    • Webhooks
    • Changelog
  • Tutorial
    • About the tutorial
    • Module 1: Build a legislation reader
      • Introductory concepts
      • Create a basic Django app
      • Create database models
      • Fetching the data
      • Work listing page
      • Expression detail page
      • Styling with Law Widgets
      • Adding interactivity
      • Staying up to date
    • Module 2: Enrichments and interactivity
      • Basic enrichments
      • Advanced enrichments
      • Advanced interactivity
    • Module 3: Text extraction for search and analysis
      • Why extracting text is important
      • Basics of text extraction
      • Advanced text extraction
      • Extracting text for analysis and machine learning
  • Content API Reference
    • About the Content API
    • Authentication
    • Pagination
    • Places
    • All work expressions
    • Single work expression
      • Commencements
      • Embedded images
      • Publication document
      • Table of Contents
      • Timeline
    • Taxonomy topics
    • Enrichment datasets
  • AI API Reference
    • About the AI API
    • Authentication
    • Knowledge Bases
  • How-to Guides
    • How to use the Table of Contents API
    • How to download images
Powered by GitBook
On this page
  • Add a webhook
  • Delete a webhook
  • Webhook invocation details
  • Handling a webhook invocation
  • Retries
  • Duplicate invocations
  • Handling deletions
  1. Get Started

Webhooks

Webhooks are push notifications when a work is created, updated or deleted.

PreviousWorks and expressionsNextChangelog

Last updated 1 year ago

You can add a webhook URL in your accounts page on Laws.Africa at .

When a Work Expression is created, updated or deleted, will send a POST request to the webhook URL with details of the action in JSON in the body of the request.

Add a webhook

  1. Visit

  2. Under Add a new webhook fill in the URL field with your webhook URL.

  3. Click Add webhook

Delete a webhook

  1. Click the Delete button alongside the webhook you wish to delete.

Webhook invocation details

The body of a webhook invocation request contains the following information:

{
  "invocation_id": "abc-123", // unique ID for this invocation; re-used if the invocation fails and is retried
  "request_id": "def-456",    // unique request ID for this HTTP request, never re-used
  "action": "updated",        // or "created" or "deleted"
  "object": "work",
  "work": {
    "frbr_uri": "/akn/za/act/2009/1",
    "url": "https://api.laws.africa/v3/akn/za/act/2009/1"
  }
}

Handling a webhook invocation

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.

Retries

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).

Duplicate invocations

Handling deletions

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!).

Visit

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.

It is possible for a work to be updated rapidly in quick succession. 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. cannot guarantee exactly-once delivery of a webhook invocation.

Therefore, rather than immediately deleting a work when getting a “deleted” webhook, first call the 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.

https://edit.laws.africa/accounts/profile/webhooks
Laws.Africa
Laws.Africa
Laws.Africa
Laws.Africa
https://edit.laws.africa/accounts/profile/webhooks
Laws.Africa
https://edit.laws.africa/accounts/profile/webhooks