Webhooks
Inbound is push-first. Each accepted message is POSTed to your endpoint as JSON, signed so you can tell a real event from a forged one.
Create an endpoint
curl -X POST "$AMB_API/v1/webhooks" \
-H "Authorization: Bearer $AMB_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/hooks/agentmailbox","events":["message.received"]}'
The response includes the endpoint id and the signing secret. Store the secret; it is shown once.
The event
{
"type": "message.received",
"inbox_id": "inx_...",
"delivery_id": "dlv_...",
"message": {
"id": "msg_...",
"thread_id": "thr_...",
"from": "jamie@example.com",
"to": "support@acme.com",
"subject": "Can't update my card",
"text": "The card form keeps failing.",
"attachments": [{ "name": "card.png", "bytes": 184320 }]
}
}
Signatures
Each request carries:
x-amb-signature: t=1763...,v1=8f2c9a...
The signed payload is <timestamp>.<raw body>, hashed with HMAC-SHA256 using the endpoint secret. Reject a timestamp older than five minutes, then compare the digest in constant time.
import { createHmac, timingSafeEqual } from "node:crypto";
export function verify(rawBody, header, secret) {
const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
const age = Math.abs(Date.now() / 1000 - Number(parts.t));
if (age > 300) return false;
const expected = createHmac("sha256", secret).update(`${parts.t}.${rawBody}`).digest("hex");
return timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}
Verify against the raw body, before JSON parsing. A framework that has already consumed the stream has to be configured to keep it.
Retries and replay
- A non-2xx response or a timeout is retried with backoff. The schedule is published in the dashboard.
- Every delivery has an id. Deduplicate on
delivery_id, not on message id: the same message can be legitimately delivered to more than one endpoint. - Failed deliveries can be replayed from the API or the dashboard. Replay reuses the original payload and delivery id, so consumers stay idempotent.
- Replays do not consume message units.
Inspect deliveries
| Method | Path |
|---|---|
GET |
/v1/webhooks |
POST |
/v1/webhooks |
DELETE |
/v1/webhooks/{id} |
GET |
/v1/webhooks/{id}/deliveries |
Delivery records show the response status, attempt count, and the next scheduled attempt.