printpipe.io
Docs: Async & callbacks

Async & callbacks

PlusProEnterprise

Add callBackUrl to convert in the background. The API answers 202 immediately and POSTs the result to your URL when it's ready:

curl https://api.printpipe.io/v1/generate \
  -H "X-API-Key: $API_KEY" -H "Content-Type: application/json" \
  -d '{"html": "https://example.com", "callBackUrl": "https://your-app.example/pdf-ready", "state": "order-42-7f3c9a"}'

# HTTP/1.1 202 Accepted
# {"status": "accepted"}
POST https://your-app.example/pdf-ready
Content-Type: application/json
X-Webhook-Signature: t=1795200000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd

{
  "document": "JVBERi0xLjcKJeLjz9MK...",   // the PDF (or image), base64
  "state": "order-42-7f3c9a",
  "contentType": "application/pdf"
}
  • Any HTTP response from your endpoint counts as delivered. An unreachable endpoint is retried twice (after 10 s and 60 s).
  • No callback is sent when the conversion fails, so put a timeout on your side.
  • Every callback is signed. X-Webhook-Signature holds a timestamp and an HMAC-SHA256 of <timestamp>.<raw body>, made with the callback signing secret of the API key that made the request (in your dashboard, under each key; every key has its own, and rotating a key keeps it). Check it, and reject timestamps older than a few minutes (see below).
  • The URL must be publicly reachable; private and internal addresses are refused.

Checking the signature

In Node.js; any HMAC-SHA256 library works the same way. Sign the body exactly as it arrived, before parsing it as JSON.

import { createHmac, timingSafeEqual } from 'node:crypto';

// rawBody: the request body exactly as received (a string, before JSON.parse).
function isGenuineCallback(rawBody, signatureHeader, secret) {
  const { t, v1 } = Object.fromEntries(signatureHeader.split(',').map((p) => p.split('=')));
  if (Math.abs(Date.now() / 1000 - Number(t)) > 300) return false; // older than 5 minutes
  const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex');
  return v1.length === expected.length && timingSafeEqual(Buffer.from(v1), Buffer.from(expected));
}