Guide
Completion webhooks and signatures
Register an HTTPS destination, verify the HMAC-SHA256 signature over the raw body, deduplicate events and recover from failures.
Purpose and scope
A webhook is an optional completion notification for requests. It does not replace the status/result endpoints. Register a public HTTPS destination on port 443, store the one-time signing secret, and verify every delivery before parsing or acting on it. Polling remains the recovery path when a delivery is delayed or lost.
There are two ways to attach one. A workspace subscription (POST /v1/webhook-subscriptions) notifies you about future requests that match its operation and event filters. A request-scoped webhook is declared inside the POST /v1/requests body and is created in the same call that accepts the work, so one job can report back to one destination without touching the workspace’s standing subscriptions.
A webhook that belongs to one request
- Send webhook: { "url": "https://…", "event_types": ["request.completed"] } with mode=async. event_types is optional and defaults to request.completed; request.completed is the only completion event of a request.
- The 202 body answers with webhook.configured, webhook.endpoint_id, webhook.event_type, the signature_headers to verify and webhook.signing_secret. That secret is returned once, on this response only.
- The destination is validated before anything is stored. A rejected URL returns webhook_url_invalid, webhook_host_unavailable, webhook_destination_not_public or webhook_event_type_unknown with 400, and no request is created; a deployment without webhook delivery answers 503 webhook_unavailable or webhook_encryption_unavailable instead of storing an endpoint it cannot sign.
- A webhook is rejected for mode=sync (webhook_requires_async): a synchronous call has no later completion to report.
- Replaying the same Idempotency-Key returns the existing request without its signing secret, and the replay must repeat the original webhook block. A replay that drops the webhook, names a different URL, or adds a webhook to a request accepted without one fails with 409 idempotency_key_conflict.
Destination rules
- HTTPS only on port 443, public destination, no embedded credentials, fragment or redirect.
- Filter by operation IDs on a workspace subscription; an empty list means all operations. A request-scoped webhook needs no filter because it belongs to one request.
- The signing secret is returned only on creation and rotation. Store it before leaving the page.
- A revoked destination cannot be updated or rotated; create a new one.
Verify the raw body (Node.js)
import { createHmac, timingSafeEqual } from "node:crypto";
export function verify(rawBody, headers, secret) {
const timestamp = headers["x-datapi-timestamp"];
const [scheme, signature] = (headers["x-datapi-signature"] ?? "").split("=");
if (scheme !== "v1" || !signature) return false;
const age = Math.abs(Date.now() / 1000 - Number(timestamp));
if (!Number.isFinite(age) || age > 300) return false;
const expected = createHmac("sha256", secret)
.update(timestamp + "." + rawBody)
.digest("hex");
const received = Buffer.from(signature, "hex");
const wanted = Buffer.from(expected, "hex");
return received.length === wanted.length && timingSafeEqual(received, wanted);
}X-DataPI-Signature carries the v1 scheme and the hex HMAC-SHA256 of "<timestamp>.<raw body>". X-DataPI-Timestamp is the signed time, X-DataPI-Event-Id identifies the event and X-DataPI-Delivery-Attempt counts the attempt. Use the exact bytes received, before JSON parsing, and compare in constant time.
Completion delivery body
{
"id": "e03e46d3-e66b-490c-aee1-e8900c3e3699",
"type": "request.completed",
"api_version": "1",
"created_at": "2026-10-27T10:00:05+00:00",
"data": {
"request_id": "9c50c1ab-8ca2-4e94-a44c-c67374b9d607",
"operation": "social.instagram.profile.read",
"status": "succeeded",
"phase": "completed",
"created_at": "2026-10-27T10:00:00+00:00",
"finished_at": "2026-10-27T10:00:04+00:00",
"status_url": "https://api.datapi.ir/v1/requests/9c50c1ab-8ca2-4e94-a44c-c67374b9d607",
"result_url": "https://api.datapi.ir/v1/requests/9c50c1ab-8ca2-4e94-a44c-c67374b9d607/result",
"result": {
"available": true,
"expired": false,
"url": "https://api.datapi.ir/v1/requests/9c50c1ab-8ca2-4e94-a44c-c67374b9d607/result",
"expires_at": "2026-10-28T10:00:04+00:00",
"retention_hours": 24
},
"error": null
}
}data repeats the fields a receiver needs from the status record: request_id, operation, status, phase, created_at, finished_at, status_url, result_url, result and error. result_url is null unless the result is readable, while result always carries url and available so a receiver can reconcile a failed request without guessing.
Delivery states
| State | Meaning | Receiver action |
|---|---|---|
| delivered | Destination returned an accepted response | Persist event_id and process once |
| retrying | A retry is scheduled with the same event | Deduplicate by event_id; keep the endpoint idempotent |
| failed | Retries exhausted or destination rejected | Recover by polling the request status/result |
Events are at-least-once
Related pages
- Requests, states and resultsThe asynchronous request lifecycle: the 202 acceptance record, status versus phase, when a stored result can actually be read, idempotent replays and how to recover from each terminal state.
- Error envelope and status codesEvery error has one shape, a stable code and a request ID for support without leaking provider details.
- Usage, limits and retentionWhat each monthly plan includes, which technical limits apply, and which limits are operation-specific rather than global promises.