DataPI.

What would you like to understand?

Preparing search…
    All results and search filters →

    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)

    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

    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

    StateMeaningReceiver action
    deliveredDestination returned an accepted responsePersist event_id and process once
    retryingA retry is scheduled with the same eventDeduplicate by event_id; keep the endpoint idempotent
    failedRetries exhausted or destination rejectedRecover by polling the request status/result

    Events are at-least-once

    Related pages

    Runtime contract snapshot: DataPI API v1.0.0 · 75 HTTP operations documented of 265 runtime operations · 40 catalog operations · 11 available at capture. Captured: . Source: https://api.datapi.ir/v1/contracts.