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/{format}​

Generate a document from a document definition sent as a JSON request body. Append the desired output format to the endpoint path.

Endpoint​

POST /api/v1/{'tenantId'}/documents/generate-from-payload/{format}
formatOutput
pdfPDF document (default)
docxWord document
svgSVG image (first page)

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, "fontWeight": "bold", "color": "#1A1A2E" },
"body": { "fontSize": 10, "color": "#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/{'tenantId'}/assets/docs/doc-20260330-143022-abc123.pdf"
}

The fileName and contentType reflect the requested format (e.g. .docx / application/vnd.openxmlformats-officedocument.wordprocessingml.document for DOCX).

Error (400 Bad Request)

{
"message": "The document definition must have valid content."
}

Example​

curl -X POST https://api.docpayload.com/v1/{'tenantId'}/documents/generate-from-payload/pdf \
-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/{'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/{'tenantId'}/assets/docs/doc-20260330-143022-abc123.pdf"
}
]

GET /documents/{fileName}​

Download a previously generated document by file name.

Endpoint​

GET /api/v1/{'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 document file as binary content with the content type matching the format (application/pdf, application/vnd.openxmlformats-officedocument.wordprocessingml.document, or image/svg+xml).

Error (404 Not Found)

{
"message": "Document not found."
}

Example​

curl -X GET https://api.docpayload.com/v1/{'tenantId'}/documents/doc-20260330-143022-abc123.pdf \
-H "Authorization: Bearer dp_live_abc123def456" \
-o downloaded.pdf