Docs / Webhooks

Platform

Webhooks

A webhook is an HTTP POST DevilPDF sends to your server when something finishes. Use them with async renders and batches so you never have to poll.

#Add an endpoint

Add endpoints in the dashboard under Webhooks, or through the API.

curl https://devilpdf.com/v1/webhooks \
  -H "Authorization: Bearer $DEVILPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/hooks/devilpdf",
    "events": ["document.succeeded", "document.failed"]
  }'
Response
{
  "object": "webhook",
  "id": "whk_PGgbPmNMKw0a1shpuiPu",
  "url": "https://example.com/hooks/devilpdf",
  "events": ["document.succeeded", "document.failed"],
  "enabled": true,
  "last_status": null,
  "last_attempt_at": null,
  "created_at": "2026-03-14T14:02:10.588Z",
  "signing_secret": "whsec_T6zJFc7DjxqxIcvhwa7d3rINq2Lm8XpY"
}
FieldTypeDescription
urlstringRequired. A public https URL.
eventsarrayEvent types to receive. Leave it out to receive all of them.

An account can have up to 10 endpoints. List them with GET /v1/webhooks and remove one with DELETE /v1/webhooks/:id.

#One-off webhooks

To be notified about a single document without adding an endpoint, pass webhook_url on the render request. It receives that document's document.succeeded or document.failed event, signed the same way.

#Events

EventSent whendata
document.succeededA document has rendered and been stored.The document, with its url.
document.failedA document could not be rendered.The document, with error.
batch.completedEvery document in a batch has finished.{ "object": "batch", "id", "total", "succeeded", "failed" }

Document events fire for every render, synchronous or async, and whichever way it was started: API, dashboard or MCP. PDF tools do not send events.

#Payload

{
  "id": "evt_dUo8MnOy2yAozbGdRGKx",
  "type": "document.succeeded",
  "created_at": "2026-03-14T14:02:11.000Z",
  "data": {
    "object": "document",
    "id": "doc_nWWGc4ehhC44vpOsHFGn",
    "status": "succeeded",
    "format": "pdf",
    "url": "https://devilpdf.com/f/doc_nWWGc4ehhC44vpOsHFGn/invoice.pdf?exp=1773532800&sig=8fe4b5c6330ae0d9427ba7e78b54a66c",
    "filename": "invoice.pdf",
    "pages": 1,
    "bytes": 29384,
    "template": "invoice",
    "batch": null,
    "metadata": { "order_id": "8813" },
    "error": null
  }
}

Use the metadata you set on the render to match the event to a record on your side.

#Headers

HeaderValue
devilpdf-signaturet=<unix timestamp>,v1=<signature>
devilpdf-eventThe event type, for example document.succeeded.
devilpdf-event-idThe event id. The same on every retry of this event.
user-agentDevilPDF-Webhooks/1.0

#Verify the signature

Anyone can post to your URL, so check that an event really came from DevilPDF before you trust it.

Every account has one signing secret, starting with whsec_. It is shown in the dashboard under Webhooks and returned when you create an endpoint. All events for your account are signed with it.

The signature is an HMAC-SHA256 of the timestamp, a dot, and the raw request body, written as hex:

v1 = HMAC_SHA256(signing_secret, t + "." + raw_body)

To verify:

  1. Read t and v1 from the devilpdf-signature header.
  2. Compute the HMAC over t + "." + body, using the raw body exactly as received, before any JSON parsing.
  3. Compare it with v1 using a constant-time comparison.
  4. Reject events whose timestamp is more than five minutes old, to stop replays.
import crypto from "node:crypto";
import express from "express";

const app = express();
const SECRET = process.env.DEVILPDF_WEBHOOK_SECRET; // whsec_...

function verify(rawBody, header) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  if (!parts.t || !parts.v1) return false;
  if (Math.abs(Date.now() / 1000 - Number(parts.t)) > 300) return false;
  const expected = crypto.createHmac("sha256", SECRET).update(`${parts.t}.${rawBody}`).digest("hex");
  const a = Buffer.from(expected);
  const b = Buffer.from(parts.v1);
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

// express.raw keeps the body as bytes, which is what the signature covers.
app.post("/hooks/devilpdf", express.raw({ type: "application/json" }), (req, res) => {
  const raw = req.body.toString("utf8");
  if (!verify(raw, req.get("devilpdf-signature") ?? "")) return res.sendStatus(400);

  const event = JSON.parse(raw);
  if (event.type === "document.succeeded") {
    console.log("ready:", event.data.id, event.data.url);
  }
  res.sendStatus(200);
});

app.listen(3000);

#Respond quickly

Return any 2xx status within 15 seconds. Anything else, including a redirect or a timeout, counts as a failure. Do slow work after you have responded: put the event on your own queue and return 200 straight away.

#Retries

A failed delivery is retried with growing delays: after 30 seconds, 2 minutes, 8 minutes and 32 minutes. After five attempts in total, the event is dropped.

Two consequences for your handler:

  • Events can arrive more than once. Use devilpdf-event-id (or id in the body) to skip ones you have already handled.
  • Events can arrive out of order. Do not assume batch.completed arrives after the last document event.

Each endpoint records the HTTP status of its most recent delivery in last_status and last_attempt_at, so you can spot one that is failing. A status of 0 means your server could not be reached.

#Test locally

Your endpoint must be reachable from the internet. During development, expose your machine with a tunnel such as cloudflared tunnel --url http://localhost:3000 or ngrok, and add the tunnel's https URL as an endpoint.