Skip to main content

Documents API

Generate documents by sending a JSON document definition to the API.

Machine-readable specs:

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

HeaderValueRequired
AuthorizationBearer YOUR_API_KEYYes
Content-Typeapplication/jsonYes

Path parameters

ParameterTypeDescription
tenantIdstringYour 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

HeaderValueRequired
AuthorizationBearer YOUR_API_KEYYes

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

HeaderValueRequired
AuthorizationBearer YOUR_API_KEYYes

Path parameters

ParameterTypeDescription
tenantIdstringYour tenant identifier
fileNamestringThe 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