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"]
}'{
"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"
}| Field | Type | Description |
|---|---|---|
url | string | Required. A public https URL. |
events | array | Event 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
| Event | Sent when | data |
|---|---|---|
document.succeeded | A document has rendered and been stored. | The document, with its url. |
document.failed | A document could not be rendered. | The document, with error. |
batch.completed | Every 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
| Header | Value |
|---|---|
devilpdf-signature | t=<unix timestamp>,v1=<signature> |
devilpdf-event | The event type, for example document.succeeded. |
devilpdf-event-id | The event id. The same on every retry of this event. |
user-agent | DevilPDF-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:
- Read
tandv1from thedevilpdf-signatureheader. - Compute the HMAC over
t + "." + body, using the raw body exactly as received, before any JSON parsing. - Compare it with
v1using a constant-time comparison. - 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);import hashlib, hmac, json, os, time
from flask import Flask, abort, request
app = Flask(__name__)
SECRET = os.environ["DEVILPDF_WEBHOOK_SECRET"] # whsec_...
def verify(raw_body: bytes, header: str) -> bool:
parts = dict(p.split("=", 1) for p in header.split(",") if "=" in p)
t, v1 = parts.get("t"), parts.get("v1")
if not t or not v1:
return False
if abs(time.time() - int(t)) > 300:
return False
expected = hmac.new(SECRET.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, v1)
@app.post("/hooks/devilpdf")
def devilpdf_hook():
raw = request.get_data()
if not verify(raw, request.headers.get("devilpdf-signature", "")):
abort(400)
event = json.loads(raw)
if event["type"] == "document.succeeded":
print("ready:", event["data"]["id"], event["data"]["url"])
return "", 200#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(oridin the body) to skip ones you have already handled. - Events can arrive out of order. Do not assume
batch.completedarrives 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.