KoboToolbox webhooks in production: duplicates, ordering, retries and timeouts

Published · Updated

This guide covers the problems KoboToolbox REST Services cause in production and how to handle each one. What KoboToolbox sends and how it works is on the KoboToolbox webhooks overview, and the Basic credential check is on Verify KoboToolbox webhooks. REST Services have no event types, so there's no list of events to read.

KoboToolbox's help page on REST Services is short, so some details here come from kpi, the open-source code that implements the sender. A self-hosted server runs its own release of kpi, so its behaviour can differ.

At a glance

ProblemWhat to doWith Event Gateway
TimeoutsReturn a 2xx within 30 seconds; process in a background jobAccepts the request at once, then queues it for your service
DuplicatesDeduplicate on _uuid, and include it in any subset of fieldsDrops repeats before they reach your handler
OrderingDon't depend on arrival orderLogs every request and attempt, so you can see arrival order when debugging
RetriesReturn 503 for temporary problems; reconcile through the API after an outageAccepts submissions while your service is down and retries on your schedule
Telling projects apartUse a URL or custom wrapper per projectRoutes on the path, headers or body
TestingSubmit a record through a public URLForwards to localhost and replays past requests
Other limitsSync edits separately; plan for bursts and form changesDelivers at a rate you set

KoboToolbox webhook timeouts and slow handlers

Return a 2xx status within 30 seconds, then do the work in a background job.

Why it happens: The kpi sender waits 30 seconds for a response. KoboToolbox's help page doesn't state a timeout. A handler that writes to several systems or fetches attachments before responding can run past it, and a read timeout counts as a failed delivery that gets retried.

Fix it in your handler:

  1. Check the Basic credentials, store the raw submission and return 200.
  2. Process the submission from a queue. See why to process webhooks asynchronously.

With Event Gateway: Hookdeck accepts each KoboToolbox request immediately, then queues it and delivers it to your service at a rate it can handle, so your handler can take as long as it needs without failing a delivery.

Duplicate KoboToolbox submissions

The same submission can reach you more than once. Store _uuid and skip repeats.

Why it happens: If your handler finishes but responds after 30 seconds, kpi retries a submission you've already stored. Retrying a failed delivery by hand sends it again as well. kpi also marks a delivery interrupted by a worker failure as failed and warns that it may already have reached your endpoint, so retrying one of those can repeat it.

Fix it in your handler:

  1. Record each _uuid in a table with a unique constraint, and skip submissions you've seen. See our guide to webhook idempotency.
  2. If the service sends a subset of fields, include _uuid in the subset. A subset leaves out everything you don't list, metadata included.
  3. For an XML service, log a real delivery and choose your key from it, because KoboToolbox doesn't document the XML body.

With Event Gateway: Hookdeck deduplicates requests before they reach your endpoint, so repeats are filtered before your handler runs.

Out-of-order KoboToolbox submissions

KoboToolbox doesn't document any ordering, so don't depend on arrival order.

Why it happens: kpi sends each submission through its own background job, and a retried delivery waits while later submissions go out. A form filled in offline also reaches the server well after it was collected.

Fix it in your handler:

  1. Treat each submission as an independent record keyed on _uuid.
  2. If order matters for your analysis, sort on a time your form records, or on _submission_time, which is when the server received it. Don't sort on arrival.

With Event Gateway: Hookdeck logs every request and attempt, so you can see the order they arrived in when debugging.

KoboToolbox webhook retries and failures

KoboToolbox retries only 3 times and only for some failures, so return 503 for a temporary problem and reconcile through the API after an outage.

Why it happens: KoboToolbox's help page says the background task retries 3 times, after 60, 600 and 6,000 seconds, which is about two hours. The current kpi code declares a different schedule, an exponential backoff starting at 60 seconds and capped at 1,200 seconds, so plan for retries to end much sooner than the help page says. In kpi, only 502, 503, 504 and read timeouts are retried. A 500, a 4xx or a connection that never opens fails at once, so a host that refuses the connection gets no retries at all.

Once a delivery has failed, it stays failed until someone retries it. KoboToolbox keeps the submission, so nothing is lost on its side, but nothing reaches your system either.

Fix it in your handler:

  1. Return 503 rather than 500 for a temporary problem in your own code.
  2. Keep email notifications on for the service, so you hear about failures. kpi sends the report once a day.
  3. Retry failed deliveries from the service's log, or all at once through the API, once you've fixed the problem.
  4. After an outage, compare recent submissions from the KoboToolbox API with what you stored, and don't count on the retries having covered it.

With Event Gateway: Hookdeck accepts and stores each submission as it arrives, then delivers to your service with retries you configure. Issues alert you when deliveries fail, and you can replay any submission once your service is back.

Telling KoboToolbox projects apart

A REST Service has one trigger and no event type, so there's nothing to subscribe to or filter by event. Give each project its own URL or label instead.

Why it happens: Every request is a new submission, and KoboToolbox adds no event type. _xform_id_string identifies the form, but a subset of fields leaves it out unless you list it.

Fix it in your handler:

  1. Give each project's service its own path, so the URL identifies the project.

  2. Or, on a JSON service, add a custom wrapper. KoboToolbox replaces %SUBMISSION% with the submission's JSON:

    { "source": "household-survey", "submission": %SUBMISSION% }
    
  3. Use a subset of fields if a downstream system should see only some answers.

With Event Gateway: Hookdeck filters match on headers and the body, so one source can send each project's submissions to its own destination.

Testing and debugging KoboToolbox webhooks

Submit a real record through a public URL, because KoboToolbox documents no test delivery.

Why it's awkward: Only a new submission fires the service, and the body depends on your form, so a generic sample won't match what your parser sees. kpi also blocks requests to private addresses, so a local URL won't work.

What to do:

  1. Point the service at a public URL that forwards to your machine. hookdeck listen 3000 kobotoolbox --path /webhooks/kobotoolbox gives you one.
  2. Submit a record from a web form or KoboCollect, and write your parser against what arrives.
  3. Check the service's log in KoboToolbox for each delivery's status code and response.

With Event Gateway: The Hookdeck CLI receives webhooks on your machine without a public server, and you can replay past requests while you work on your handler.

Other KoboToolbox webhook limits

Edits never arrive. Data is sent only on creation, and nothing is sent when a submission is edited, so a record corrected after review stays wrong in your system. Treat the REST Service as the fast path and sync edits on a schedule through the KoboToolbox API.

Offline collection means bursts. KoboCollect stores submissions offline and uploads them when it has a connection, and each one triggers its own request. A team returning from the field can send a day's submissions within minutes, so size your endpoint for peak uploads rather than the daily average.

Forms change. Keys in the body are your question names, and groups and repeat groups change how they nest. Adding, renaming or regrouping questions changes the body, so parse defensively and keep the raw submission so you can reprocess it.

No published source IPs. KoboToolbox doesn't publish a list of addresses, and self-hosted servers send from wherever they run, so an IP allowlist isn't an option. Rely on the Basic credentials over HTTPS, with a long random password and a separate pair per project.

With Event Gateway: Hookdeck absorbs a burst and delivers to your service at a max delivery rate you set. It also checks the Basic username and password on every request, and a request that doesn't match never reaches your destination.

Keep an outage from costing you KoboToolbox field data.

Event Gateway checks the Basic credentials, stores each submission as it arrives and delivers it to your service with retries you control, so a long outage on your side costs latency rather than submissions.

Not affiliated with KoBoToolbox. Facts are compiled from public sources and linked inline.