Webhooks you can trust: signature, retries and catching up
An incident is only useful if your back end hears about it, once, and can prove who sent it. The signature check, the retry schedule and the catch-up call, with code.
A monitor that opens an incident has done half the job. The other half is telling your back end, and a webhook is the usual way: Camly posts a JSON message to an address of yours when something happens and when it ends.
A webhook endpoint is also a public address that accepts messages from the internet. Three questions decide whether you can trust what arrives there: who sent it, did I already handle it, and what did I miss while I was down. The API has an answer for each.1
Create an endpoint
curl https://api.camly.ai/v1/webhook-endpoints \
-H "Authorization: Bearer $CAMLY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/camly",
"event_types": ["incident.opened", "incident.closed"]
}'
The address must be public https. The answer carries a secret that starts with whsec_, shown once: store it where your endpoint can read it. Leave event_types empty to receive every event.
What arrives
{
"id": "evt_123",
"object": "event",
"type": "incident.opened",
"mode": "live",
"data": { "incident": { "id": "inc_123", "...": "..." } },
"created": "2026-11-06T09:30:12.482913Z"
}
The events fall into four families.
| Family | Events | Typical use |
|---|---|---|
| Incidents | incident.opened, incident.updated, incident.closed | Raise, refresh and clear an alert |
| Health | camera.offline, camera.online, bridge.offline, bridge.online | Show that a camera is no longer analysed |
| Money | billing.balance_low, billing.recharge_failed, budget.threshold_reached, monitor.paused, monitor.resumed | Warn an administrator before monitoring stops |
| The past | lookback.finished, pictures.ready, picture.kept, picker.chosen | Continue a search that was started earlier |
The health family is the one teams forget. An integration that only listens to incident.opened cannot tell “nothing happened tonight” from “the camera was unplugged at six”. Map camera.offline to something visible.
Question one: who sent it
Every delivery has a header:
Camly-Signature: t=1762421412,v1=5257a8...
t is the Unix time. v1 is the HMAC-SHA256, in hex, of t, a dot and the raw body, keyed with your endpoint’s secret. Check it before you do anything else:
import hashlib, hmac, json, time
def verify(body: bytes, header: str, secret: str, tolerance: int = 300) -> dict:
parts = dict(p.split("=", 1) for p in header.split(","))
signed = f"{parts['t']}.".encode() + body
expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
if not hmac.compare_digest(expected, parts["v1"]):
raise ValueError("bad signature")
if abs(time.time() - int(parts["t"])) > tolerance:
raise ValueError("too old")
return json.loads(body)
Two mistakes account for most failed checks.
Checking the parsed body. The signature covers the bytes exactly as received. A framework that parses the JSON and gives you back an object has already lost them: re-serialising changes spaces and key order, and the signature no longer matches. Read the raw body first, verify, then parse.
Skipping the time check. Without it, anyone who captured one valid message can replay it for ever. Refuse a t more than five minutes away.
Ready-made helpers exist for Python and JavaScript, one file each and no dependency, if you would rather not copy the function.1
Question two: did I already handle it
Delivery is at least once. The same event can arrive twice, and events can arrive out of order. Both are normal behaviour for any webhook system that retries, not a fault.
- Deduplicate on the event
id, which is also in theCamly-Event-Idheader. A table of handled ids with a unique constraint is enough. - Do not assume
incident.closedarrives afterincident.opened. Use the timestamps inside the incident, not the order of arrival.
Answer with a 2xx within 10 seconds. Anything else counts as a failed attempt, and redirects are not followed. If handling takes longer, put the event on a queue, answer 200, and work afterwards.
Question three: what did I miss
Failed attempts are retried for about 24 hours, at growing intervals: 30 seconds, then 2, 10 and 30 minutes, then 1, 2, 4, 8 and 8 hours. A deployment that takes your endpoint down for ten minutes loses nothing.
A longer outage does not lose anything either, because events are kept whatever happens to their deliveries. Keep the id of the last event you handled and ask for what followed:
curl "https://api.camly.ai/v1/events?after=evt_123" \
-H "Authorization: Bearer $CAMLY_API_KEY"
The events come oldest first; repeat while has_more is true. POST /v1/events/evt_123/redeliver sends one again to every endpoint that wants it, which is also a handy way to test your deduplication.
A minimal handler, in order
- Read the raw body.
- Verify the signature and the time. On failure, answer 400.
- Look up the event
id. If it is already handled, answer 200 and stop. - Store the event, answer 200.
- Do the real work from the stored event.
Unknown event types will appear as the API grows, and an endpoint with empty event_types receives them too. Step 5 should ignore what it does not know rather than fail.
Test it without a camera
An endpoint created with a test key receives the events of test objects, signed like live ones. A simulated camera opens and closes an incident on demand, so the whole handler can be built and tested before any real camera exists.1
Sources
- Camly API, all guides as plain text: Webhooks, Testing without cameras. platform.camly.ai
- Camly API contract (OpenAPI). api.camly.ai