Webhooks optional, signed
If you registered a webhook_url, we POST it once when the batch is delivered, so you do not have to poll. The body is the same shape as the delivered GET /results response:
POST https://your-app.com/hooks/senebiclabs
Content-Type: application/json
X-Senebiclabs-Signature: sha256=<hex>
X-Senebiclabs-Timestamp: 1760000000
X-Senebiclabs-Event-Id: 6f1c2a9e-...
{
"event": "results.delivered",
"project_id": "...",
"company": "Your Company",
"report": { ... },
"items": [ ... ]
}Verify the signature
Every webhook carries three headers. X-Senebiclabs-Signature is an HMAC-SHA256, keyed with your webhook_secret, over the timestamp and the request body joined by a dot: <timestamp>.<raw body>.X-Senebiclabs-Timestamp is the Unix second we sent it, and X-Senebiclabs-Event-Id identifies the delivery.
Recompute the signature and compare in constant time before you trust the payload, and reject anything whose timestamp is older than a few minutes. The signature proves the request came from us unaltered; the timestamp is what stops a captured payload being replayed against you later. Store the event id and ignore one you have already processed, so a redelivery cannot be counted twice.
Compute over the raw request bytes, before any JSON parsing. Parsing and re-serialising can change the bytes and break the check.
import hmac, hashlib, time
TOLERANCE = 300 # seconds
def verify(raw_body: bytes, sig: str, ts: str, secret: str) -> bool:
if not ts.isdigit() or abs(time.time() - int(ts)) > TOLERANCE:
return False # too old, or from the future: a replay
signed = ts.encode() + b"." + raw_body
expected = "sha256=" + hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, sig or "")
# FastAPI example
@app.post("/hooks/senebiclabs")
async def hook(request: Request):
raw = await request.body()
sig = request.headers.get("X-Senebiclabs-Signature", "")
ts = request.headers.get("X-Senebiclabs-Timestamp", "")
if not verify(raw, sig, ts, WEBHOOK_SECRET):
raise HTTPException(status_code=401)
event_id = request.headers.get("X-Senebiclabs-Event-Id", "")
if already_processed(event_id): # a redelivery; acknowledge and stop
return {"ok": True}
payload = json.loads(raw) # trusted from here
...Return 2xx to acknowledge. A 5xx or a refused connection is retried up to three times (immediately, then after 2s and 6s) — that pattern means your endpoint blipped. If all three fail, we keep trying on a schedule with growing gaps (minutes at first, then hours) before giving up. A 4xx is never retried: your service rejected the request itself, and repeating it would just deliver the same rejection.
Every attempt, scheduled retry and redelivery of the same results carries the same X-Senebiclabs-Event-Id, so a repeat of one you have already processed can be acknowledged and ignored.
The outcome is recorded and returned by GET /results once delivered, so a lost webhook is distinguishable from one that was never due:
"webhook": { "delivered": false, "status": 502, "attempts": 3, "at": "..." }For an outage longer than the retries, or a changed URL, re-send it with POST /webhook/redeliver. GET /results remains the source of truth if delivery is critical.