PDF Webhook Payload Reference | HMAC Verification & Retry
The PDF API Webhook Integration Guide explains how to set up notifications. This article is a focused reference on payload field definitions, HMAC-SHA256 signature verification, and retry behavior — everything you need when implementing or debugging a webhook receiver.
Webhooks are a SaaS edition feature available on every plan, including Free. The Open edition does not send webhooks.
Registering a Webhook and Its Secret
Register a webhook with POST /api/webhooks (requires an API key with the manage scope) or from the Webhooks screen in the dashboard.
curl -X POST https://pdf.funbrew.cloud/api/webhooks \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/webhooks/funbrew-pdf", "events": ["pdf.generated", "pdf.downloaded", "pdf.expired"]}'
data.secret in the response (201) is the secret used for signature verification. It is returned only in that registration response and is not included in the list endpoint (GET /api/webhooks). If you register on the dashboard instead, it is shown once, right after registration. Either way, store this value on the receiving side.
Top-Level Payload Structure
Every webhook request shares the same top-level shape.
{
"event": "pdf.generated",
"timestamp": "2026-05-12T10:00:00.000000Z",
"data": { ... }
}
Field Definitions
| Field | Type | Description |
|---|---|---|
event |
string | Event type (see below) |
timestamp |
string (ISO 8601, UTC, microseconds) | When the payload was built. It does not change on retries |
data |
object | Event-specific payload (see below) |
There is no per-event ID (nothing like webhook_id) and no API version field. See "Idempotent Processing" below for how to detect duplicates.
Event Types and Payload Schemas
Five events are sent. You receive only the ones listed in events when you registered the webhook.
| Event | When it fires |
|---|---|
pdf.generated |
A PDF was generated through the API (HTML / URL / Markdown / template / each batch item) |
pdf.downloaded |
A PDF was downloaded (through the API or the download page) |
pdf.expired |
An expired PDF was deleted |
tus.upload.completed |
A tus resumable upload finished |
tus.upload.aborted |
A tus upload was aborted or discarded |
pdf.generated is not sent for test-mode generation ("test": true), Playground generation, or post-processing APIs such as merge and split.
There is no event for batch completion (nothing like
batch.completed). Any event outside the five above ineventsis rejected with 422 at registration. Track batch completion with the per-itempdf.generatedevents orGET /api/pdf/batch/{batch_id}. There is also no event for failed generation (nothing likepdf.failed).
pdf.generated — PDF generation completed
{
"event": "pdf.generated",
"timestamp": "2026-05-12T10:00:00.000000Z",
"data": {
"filename": "9b2f6c1e-3d4a-4f5b-8c6d-7e8f9a0b1c2d.pdf",
"download_url": "https://pdf.funbrew.cloud/dl/AbCdEf0123456789AbCdEf0123456789",
"file_size": 48210,
"source_type": "html",
"expires_at": "2026-05-13T10:00:00.000000Z"
}
}
| Field | Type | Description |
|---|---|---|
filename |
string | Stored file name (UUID + .pdf). Use it with GET /api/pdf/download/{filename} |
download_url |
string | URL of the download page (/dl/<token>). See below |
file_size |
integer | File size in bytes |
source_type |
string | How the PDF was generated: html, url, markdown, or template |
expires_at |
string (ISO 8601) or null | Expiry time. null if generated with expiration_hours: 0 |
pdf.downloaded — PDF downloaded
Same data as pdf.generated, plus two fields.
{
"event": "pdf.downloaded",
"timestamp": "2026-05-12T10:05:00.000000Z",
"data": {
"filename": "9b2f6c1e-3d4a-4f5b-8c6d-7e8f9a0b1c2d.pdf",
"download_url": "https://pdf.funbrew.cloud/dl/AbCdEf0123456789AbCdEf0123456789",
"file_size": 48210,
"source_type": "html",
"expires_at": "2026-05-13T10:00:00.000000Z",
"download_count": 1,
"remaining_downloads": 9
}
}
| Field | Type | Description |
|---|---|---|
download_count |
integer | Number of downloads so far |
remaining_downloads |
integer | Downloads left. -1 when max_downloads: 0 (unlimited) |
pdf.expired — PDF expired
data has the same shape as pdf.generated. This event is sent during file deletion, so by the time it arrives the PDF can no longer be downloaded.
tus.upload.completed / tus.upload.aborted — Resumable uploads
{
"event": "tus.upload.completed",
"timestamp": "2026-05-12T10:00:00.000000Z",
"data": {
"upload_key": "0f1e2d3c-4b5a-6978-8796-a5b4c3d2e1f0",
"original_filename": "report.pdf",
"size": 10485760,
"storage": "local",
"s3_key": null,
"content_type": "application/pdf"
}
}
See the tus resumable upload guide for details.
About download_url
download_url points to a download page (HTML), not the PDF itself. It works as a link to send to a person, but to fetch the PDF from code use one of:
GET https://pdf.funbrew.cloud/api/pdf/download/{filename}(requiresAuthorization: Bearer <API key>)GET {download_url}/download(no authentication, up to 10 requests per minute)
Both work only within the expiry (expires_at) and max_downloads, and each fetch increments the download count and sends pdf.downloaded.
HMAC-SHA256 Signature Verification
How Signatures Work
The X-Webhook-Signature request header carries an HMAC-SHA256 of the entire request body.
X-Webhook-Signature: sha256=<hex-encoded HMAC>
The signature is computed as follows:
- The request body (JSON bytes) is the message
- The secret returned when you registered the webhook is the key
- HMAC-SHA256 is computed, hex-encoded (lowercase), and prefixed with
sha256=
The JSON body is sent with / escaped as \/. Re-serializing a parsed object will not reproduce the original bytes, so compute the HMAC over the raw body you received.
Verification by Language
Node.js
const crypto = require('crypto');
const express = require('express');
const app = express();
function verifyWebhookSignature(body, signature, secret) {
// body must stay a Buffer — never reconstruct it with JSON.stringify
const expected = 'sha256=' + crypto
.createHmac('sha256', secret)
.update(body)
.digest('hex');
const a = Buffer.from(signature);
const b = Buffer.from(expected);
// timingSafeEqual throws when the lengths differ, so compare lengths first
return a.length === b.length && crypto.timingSafeEqual(a, b);
}
// Express example
app.use('/webhooks/funbrew-pdf', express.raw({ type: 'application/json' }));
app.post('/webhooks/funbrew-pdf', (req, res) => {
const sig = req.headers['x-webhook-signature'] || '';
if (!verifyWebhookSignature(req.body, sig, process.env.WEBHOOK_SECRET)) {
return res.status(401).json({ error: 'Invalid signature' });
}
const payload = JSON.parse(req.body.toString());
// ...handle the event
res.json({ received: true });
});
app.listen(3000);
Note:
express.json()turnsreq.bodyinto an object and the raw bytes are lost. Useexpress.raw()for signature verification (express.raw()gives you the body as aBuffer).
Python (FastAPI)
import hashlib
import hmac
import json
import os
from fastapi import FastAPI, HTTPException, Request
app = FastAPI()
def verify_signature(body: bytes, signature: str, secret: str) -> bool:
expected = "sha256=" + hmac.new(
secret.encode("utf-8"),
body,
hashlib.sha256,
).hexdigest()
# compare_digest prevents timing attacks
return hmac.compare_digest(expected, signature)
@app.post("/webhooks/funbrew-pdf")
async def handle_webhook(request: Request):
body = await request.body() # raw bytes
sig = request.headers.get("x-webhook-signature", "")
if not verify_signature(body, sig, os.environ["WEBHOOK_SECRET"]):
raise HTTPException(status_code=401, detail="Invalid signature")
payload = json.loads(body)
# ...handle the event
return {"received": True}
PHP (Laravel)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class WebhookController extends Controller
{
public function handle(Request $request)
{
$signature = $request->header('X-Webhook-Signature', '');
$expected = 'sha256=' . hash_hmac(
'sha256',
$request->getContent(), // raw request body
config('services.funbrew.webhook_secret')
);
// hash_equals prevents timing attacks
if (! hash_equals($expected, $signature)) {
abort(401, 'Invalid signature');
}
$payload = $request->json()->all();
// ...handle the event
return response()->json(['received' => true]);
}
}
If you register a Slack Incoming Webhook URL (
hooks.slack.com), a Slack message is sent instead of the payload above.
Using the Timestamp (Replay Attack Prevention)
timestamp is part of the signed body, so you can trust it once the signature checks out. However, retries and manual re-deliveries from the dashboard keep the original value. Automatic retries continue until about six minutes after the first attempt, and a manual re-delivery can happen days later, so a short window such as "reject anything older than 5 minutes" will reject legitimate re-deliveries. If you reject old events, use a window well beyond the retry schedule, and rely mainly on the duplicate detection below.
function isTimestampValid(timestamp, toleranceMs = 60 * 60 * 1000) {
const eventTime = new Date(timestamp).getTime();
return Math.abs(Date.now() - eventTime) < toleranceMs;
}
Retry Behavior
FUNBREW PDF Retry Schedule
Each delivery times out after 10 seconds. Retries happen as follows.
| Response | Handling |
|---|---|
2xx |
Success |
5xx, timeout, connection error |
Failure, retried |
4xx |
Failure, not retried (treated as a receiver configuration error) |
A delivery is attempted up to 3 times, including the first attempt.
| Attempt | Timing |
|---|---|
| 1st | When the event occurs |
| 2nd (retry) | 60 seconds after the 1st fails |
| 3rd (final) | 300 seconds after the 2nd fails |
Every attempt is recorded with its response code in the "delivery log" (latest 50) on the dashboard Webhooks screen, where you can also re-deliver manually. There is no API for re-delivery.
Idempotent Processing
Retries and manual re-deliveries can deliver the same event more than once. The payload has no event ID, so use the combination of event, timestamp, and the target (data.filename or data.upload_key) as the deduplication key. These three stay the same on re-delivery, and separate downloads of the same file differ by timestamp.
const crypto = require('crypto');
const { createClient } = require('redis');
const redis = createClient({ url: process.env.REDIS_URL });
// call await redis.connect() once at startup
function dedupeKey(payload) {
const target = payload.data.filename ?? payload.data.upload_key ?? '';
return 'webhook:processed:' + crypto
.createHash('sha256')
.update(`${payload.event}|${payload.timestamp}|${target}`)
.digest('hex');
}
async function processOnce(payload, handler) {
// SET ... NX EX: only set if the key does not exist (TTL 7 days)
const isNew = await redis.set(dedupeKey(payload), '1', { NX: true, EX: 7 * 86400 });
if (!isNew) {
console.log(`Duplicate webhook ignored: ${payload.event} ${payload.timestamp}`);
return;
}
await handler();
}
app.post('/webhooks/funbrew-pdf', async (req, res) => {
// after signature verification...
const payload = JSON.parse(req.body.toString());
res.json({ received: true }); // respond first to stay within 10 seconds
setImmediate(() =>
processOnce(payload, () => handleEvent(payload.event, payload.data))
);
});
Once you have returned 200, FUNBREW PDF will not retry even if your later processing fails. For work you cannot afford to lose, enqueue it in your own queue before returning 200.
Testing Locally
Webhooks are not sent for test-mode or Playground generation. Start by sending a signed request to your receiver yourself.
# Sign a test payload and send it
SECRET="your_secret"
BODY='{"event":"pdf.generated","timestamp":"2026-05-12T10:00:00.000000Z","data":{"filename":"test.pdf","download_url":"https:\/\/pdf.funbrew.cloud\/dl\/test","file_size":1024,"source_type":"html","expires_at":null}}'
SIG=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$SECRET" | sed 's/^.*= //')
curl -X POST http://localhost:3000/webhooks/funbrew-pdf \
-H "Content-Type: application/json" \
-H "X-Webhook-Signature: sha256=$SIG" \
--data-binary "$BODY"
To receive a real delivery, expose your local server with a tool such as ngrok, register that URL, and generate a PDF through the API without test mode (it counts toward your monthly generation quota).
Summary
Key points for webhook payloads:
- Five events:
pdf.generated/pdf.downloaded/pdf.expired/tus.upload.completed/tus.upload.aborted - Verify
X-Webhook-Signatureover the raw bytes: the secret is returned only when you register through the API download_urlis a download page: fetch the PDF itself from/api/pdf/download/{filename}or{download_url}/download- Return 2xx within 10 seconds: 5xx and timeouts are attempted up to 3 times; 4xx is not retried
- Deduplicate on
event+timestamp+ target:timestampdoes not change on re-delivery
For full integration examples, see the PDF API Webhook Integration Guide. For production deployment best practices, see the PDF API Production Guide. For invoice automation with webhooks, see Automate Invoice PDF Generation.
Related
- PDF API Webhook Integration Guide — Slack and email notification setup
- PDF API Production Guide — Production best practices
- Automate Invoice PDF Generation — Invoice workflow with webhook callbacks
- API Documentation — Full API reference
- Playground — Try the API (webhooks are not sent)