Idempotency
Connections drop — especially on mobile data. Idempotency lets you retry any write without creating a second subscription, invoice or payment.
The Idempotency-Key header
Every POST accepts an Idempotency-Key header (1–255 printable ASCII characters). The first request with a key runs normally and its response is stored for 24 hours. Repeats with the same key and the same body return the stored response, byte for byte, with Idempotent-Replayed: true.
curl -X POST https://admin.heka.care/api/platform/v1/invoices/9b1f…/payments \
-H "Authorization: Bearer $HSL_API_KEY" \
-H "Idempotency-Key: momo-MP241125.1432.A12345" \
-H "Content-Type: application/json" \
-d '{"amount": 350000, "method": "mobile_money", "reference": "MP241125.1432.A12345"}'Behaviour
| Situation | Result |
|---|---|
| Same key, same body, first request finished | Stored response replayed (same status and body) |
| Same key, same body, first request still running | 409 request_in_progress — retry shortly |
| Same key, different body or path | 409 idempotency_key_reused |
| First request failed with 5xx | Nothing is stored; the retry runs fresh |
| First request failed with 4xx | The 4xx is stored and replayed — fix the request and use a new key |
| More than 24 h later | The key is forgotten and the request runs again |
Keys are per API key: two integrations can use the same string without colliding.
Usage records
Usage has a second, permanent layer: each record carries its own idempotency_key, unique per facility forever. A record whose key was already stored is skipped and counted in duplicates. You can therefore re-send a whole month of usage after an outage and only the missing records are added. See usage metering.
Choosing keys
- Derive the key from the business operation, not from the attempt:
sub-create-GH-VRH-001-2026-11, not a random value per retry. - For payments, use the MoMo transaction id or bank slip number — it is unique by nature.
- Generate a UUID once per operation if nothing natural exists, and store it with the pending operation.
reference can be used once per method. Recording the same MoMo transaction twice fails with 409.