PDFtmpl API

Public API for PDF generation from templates

Authentication

All API requests require authentication using an API key. Include your API key in the X-API-Key header with every request.

X-API-Key: your-api-key-here

API keys can be generated from the PDFtmpl application dashboard.

API Key Scope

API keys can be scoped to specific tags. When an API key has tags configured:

API keys without tags have access to all templates.

Base URL

/api/v1

Endpoints

POST /api/v1/pdf/generate

Generate a PDF from a template with custom data.

Request Headers

HeaderRequiredDescription
X-API-KeyYesYour API key
Content-TypeYesapplication/json

Request Body

{
  "templateId": "abc123XYZ0",
  "data": {
    "customerName": "John Doe",
    "invoiceDate": "2025-01-15",
    "amount": "$1,500.00"
  }
}
FieldTypeRequiredDescription
templateIdstringYesPublic ID of the template (10-character alphanumeric)
dataobjectNoKey-value pairs to replace template variables

Response 200 OK

{
  "id": 1,
  "status": "pending",
  "message": "PDF generation has been queued"
}

Errors

StatusDescription
401API key missing, invalid, or expired
400Invalid request body
403Template out of scope for this API key
404Template not found

Example

curl -X POST https://api.pdftmpl.com/api/v1/pdf/generate \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"templateId": "abc123XYZ0", "data": {"name": "John Doe"}}'

GET /api/v1/pdf/:id

Get the status and details of a PDF generation request.

Request Headers

HeaderRequiredDescription
X-API-KeyYesYour API key

Path Parameters

ParameterTypeDescription
idnumberThe PDF generation ID returned from /generate

Response 200 OK

{
  "id": 1,
  "status": "completed",
  "pdfUrl": "https://api.pdftmpl.com/pdfs/abc123.pdf",
  "error": null,
  "createdAt": "2025-01-15T10:30:00Z",
  "completedAt": "2025-01-15T10:30:05Z"
}
FieldTypeDescription
statusstringpending | processing | completed | failed
pdfUrlstring | nullURL to download the PDF (when completed)
errorstring | nullError message (when failed)

Errors

StatusDescription
401API key missing, invalid, or expired
404Generation not found

Example

curl https://api.pdftmpl.com/api/v1/pdf/1 \
  -H "X-API-Key: your-api-key"

GET /api/v1/templates

List all templates available for your account.

Request Headers

HeaderRequiredDescription
X-API-KeyYesYour API key

Query Parameters

ParameterTypeRequiredDescription
tagstringNoFilter templates by tag

Response 200 OK

{
  "templates": [
    {
      "id": "abc123XYZ0",
      "name": "Invoice Template",
      "description": "Standard invoice template",
      "width": 595,
      "height": 842,
      "tags": ["invoice", "ecommerce"],
      "createdAt": "2025-01-10T10:00:00.000Z",
      "updatedAt": "2025-01-15T14:30:00.000Z"
    }
  ]
}
FieldTypeDescription
idstringTemplate public ID (use this for /pdf/generate)
namestringTemplate name
descriptionstring | nullTemplate description
widthnumberTemplate width in pixels
heightnumberTemplate height in pixels
tagsstring[]Template tags

Errors

StatusDescription
401API key missing, invalid, or expired

Example

curl https://api.pdftmpl.com/api/v1/templates \
  -H "X-API-Key: your-api-key"

# Filter by tag
curl "https://api.pdftmpl.com/api/v1/templates?tag=invoice" \
  -H "X-API-Key: your-api-key"
Note: PDF generation is asynchronous. After calling /generate, poll the /pdf/:id endpoint to check when your PDF is ready, or configure webhooks to receive notifications automatically.

Webhooks

Webhooks allow you to receive automatic notifications when a PDF generation is completed. Instead of polling the API, you can configure webhook URLs that will receive a POST request with the generation result.

How it works

Webhooks are associated with tags. When a PDF is generated from a template:

  1. The system checks the template's tags
  2. It finds all your webhooks that have at least one matching tag
  3. Each matching webhook receives a POST notification
Example: If your template has tags ["invoice", "ecommerce"] and you have a webhook configured with tag ["invoice"], this webhook will be triggered when a PDF is generated from this template.

Webhook Configuration

Webhooks are configured in the PDFtmpl application dashboard under Settings → Webhooks. Each webhook has:

FieldDescription
nameA friendly name to identify the webhook
urlThe URL that will receive POST requests
tagsList of tags that trigger this webhook

Webhook Payload

When a PDF generation is completed, the following payload is sent via POST to each matching webhook URL:

{
  "event": "pdf.generated",
  "data": {
    "id": 1,
    "status": "completed",
    "pdfUrl": "https://api.pdftmpl.com/pdfs/abc123.pdf",
    "createdAt": "2025-01-15T10:30:00.000Z",
    "completedAt": "2025-01-15T10:30:05.000Z",
    "metadata": {
      "customerName": "John Doe",
      "invoiceDate": "2025-01-15"
    }
  }
}
FieldTypeDescription
eventstringAlways "pdf.generated"
data.idnumberThe PDF generation ID
data.statusstring"completed" or "failed"
data.pdfUrlstring | nullURL to download the PDF (when completed)
data.metadataobjectThe original data passed to /generate
Important: Webhook delivery is best-effort. If your endpoint is unavailable, the notification will not be retried. The PDF generation itself will not fail if a webhook fails to deliver.