Documents API
Generate documents by sending a JSON document definition to the API.
Machine-readable specs:
- OpenAPI Spec (JSON) — import into Postman, Insomnia, or your API gateway
- Document Definition JSON Schema — for IDE autocomplete and payload validation
POST /documents/generate-from-payload
Generate a PDF from a document definition sent as a JSON request body.
Endpoint
POST /api/v1/tenants/{'tenantId'}/documents/generate-from-payload
Headers
| Header | Value | Required |
|---|---|---|
Authorization | Bearer YOUR_API_KEY | Yes |
Content-Type | application/json | Yes |
Path parameters
| Parameter | Type | Description |
|---|---|---|
tenantId | string | Your tenant identifier |
Request body
The request body is a JSON document definition. See Document Definition for the full schema.
{
"document": {
"metadata": {
"title": "Shipment Confirmation",
"author": "ShipForge"
},
"pageSetup": {
"size": "A4",
"orientation": "portrait",
"margins": [50, 40, 50, 40]
},
"styles": {
"title": { "fontSize": 22, "bold": true, "fontColor": "#1A1A2E" },
"body": { "fontSize": 10, "fontColor": "#333333" }
},
"content": [
{ "p": "Shipment Confirmation", "style": "title" },
{ "p": "Your package has been dispatched and is on its way.", "style": "body" }
]
}
}
Response
Success (200 OK)
Returns a JSON object with the generated document metadata and a download URL.
{
"fileName": "doc-20260330-143022-abc123.pdf",
"documentId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"status": "Completed",
"fileSizeBytes": 24576,
"contentType": "application/pdf",
"downloadUrl": "https://api.docpayload.com/v1/tenants/{'tenantId'}/assets/docs/doc-20260330-143022-abc123.pdf"
}
Error (400 Bad Request)
{
"message": "The document definition must have valid content."
}
Example
curl -X POST https://api.docpayload.com/v1/tenants/{'tenantId'}/documents/generate-from-payload \
-H "Authorization: Bearer dp_live_abc123def456" \
-H "Content-Type: application/json" \
-d '{
"document": {
"content": [
{ "p": "Hello from DocPayload!" }
]
}
}'
GET /documents
List all generated documents for the tenant.
Endpoint
GET /api/v1/tenants/{'tenantId'}/documents
Headers
| Header | Value | Required |
|---|---|---|
Authorization | Bearer YOUR_API_KEY | Yes |
Response
Success (200 OK)
Returns an array of document metadata objects.
[
{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"fileName": "doc-20260330-143022-abc123.pdf",
"documentId": "d4e5f6a7-b8c9-0123-4567-89abcdef0123",
"createdAt": "2026-03-30T14:30:22Z",
"fileSizeBytes": 24576,
"contentType": "application/pdf",
"expiresAt": "2026-04-29T14:30:22Z",
"downloadUrl": "https://api.docpayload.com/v1/tenants/{'tenantId'}/assets/docs/doc-20260330-143022-abc123.pdf"
}
]
GET /documents/{fileName}
Download a previously generated PDF document by file name.
Endpoint
GET /api/v1/tenants/{'tenantId'}/documents/{fileName}
Headers
| Header | Value | Required |
|---|---|---|
Authorization | Bearer YOUR_API_KEY | Yes |
Path parameters
| Parameter | Type | Description |
|---|---|---|
tenantId | string | Your tenant identifier |
fileName | string | The file name returned from generation |
Response
Success (200 OK)
Returns the PDF file as application/pdf binary content.
Error (404 Not Found)
{
"message": "Document not found."
}
Example
curl -X GET https://api.docpayload.com/v1/tenants/{'tenantId'}/documents/doc-20260330-143022-abc123.pdf \
-H "Authorization: Bearer dp_live_abc123def456" \
-o downloaded.pdf