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:
- Only templates with at least one matching tag can be accessed
GET /templates returns only templates within the scope
POST /pdf/generate returns 403 if the template is out of scope
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
| Header | Required | Description |
X-API-Key | Yes | Your API key |
Content-Type | Yes | application/json |
Request Body
{
"templateId": "abc123XYZ0",
"data": {
"customerName": "John Doe",
"invoiceDate": "2025-01-15",
"amount": "$1,500.00"
}
}
| Field | Type | Required | Description |
templateId | string | Yes | Public ID of the template (10-character alphanumeric) |
data | object | No | Key-value pairs to replace template variables |
Response 200 OK
{
"id": 1,
"status": "pending",
"message": "PDF generation has been queued"
}
Errors
| Status | Description |
| 401 | API key missing, invalid, or expired |
| 400 | Invalid request body |
| 403 | Template out of scope for this API key |
| 404 | Template 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
| Header | Required | Description |
X-API-Key | Yes | Your API key |
Path Parameters
| Parameter | Type | Description |
id | number | The 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"
}
| Field | Type | Description |
status | string | pending | processing | completed | failed |
pdfUrl | string | null | URL to download the PDF (when completed) |
error | string | null | Error message (when failed) |
Errors
| Status | Description |
| 401 | API key missing, invalid, or expired |
| 404 | Generation 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
| Header | Required | Description |
X-API-Key | Yes | Your API key |
Query Parameters
| Parameter | Type | Required | Description |
tag | string | No | Filter 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"
}
]
}
| Field | Type | Description |
id | string | Template public ID (use this for /pdf/generate) |
name | string | Template name |
description | string | null | Template description |
width | number | Template width in pixels |
height | number | Template height in pixels |
tags | string[] | Template tags |
Errors
| Status | Description |
| 401 | API 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:
- The system checks the template's tags
- It finds all your webhooks that have at least one matching tag
- 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:
| Field | Description |
name | A friendly name to identify the webhook |
url | The URL that will receive POST requests |
tags | List 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"
}
}
}
| Field | Type | Description |
event | string | Always "pdf.generated" |
data.id | number | The PDF generation ID |
data.status | string | "completed" or "failed" |
data.pdfUrl | string | null | URL to download the PDF (when completed) |
data.metadata | object | The 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.