Skip to main content

Document Generation

Generate documents from templates by providing merge data. This guide covers single document generation, output formats, and status tracking.

Generating a Document

Provide a template ID and merge data to generate a document.

curl -X POST "https://api.propper.ai/v1/docgen/documents" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"templateId": "tmpl_abc123",
"mergeData": {
"customerName": "Acme Corp",
"invoiceNumber": "INV-2024-001",
"lineItems": [
{ "description": "Consulting", "amount": "$5,000" },
{ "description": "Development", "amount": "$10,000" }
]
},
"outputFormat": "PDF"
}'

Response:

{
"id": "doc_xyz789",
"templateId": "tmpl_abc123",
"status": "GENERATED",
"outputFormat": "PDF",
"createdAt": "2024-01-15T10:01:00Z"
}

Output Formats

FormatDescription
PDFPortable Document Format (recommended)
HTMLHTML document

Checking Document Status

Document generation may take a moment for complex templates. Poll the status endpoint to track progress.

curl "https://api.propper.ai/v1/docgen/documents/{documentId}" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Status Flow

StatusDescription
DRAFTDocument created, generation not started
GENERATINGGeneration in progress
GENERATEDDocument ready for download
FAILEDGeneration failed (check error details)

Downloading a Document

Once a document reaches GENERATED status, download it.

curl "https://api.propper.ai/v1/docgen/documents/{documentId}/download" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-o output.pdf

Listing Documents

Retrieve a paginated list of generated documents.

curl "https://api.propper.ai/v1/docgen/documents?page=1&pageSize=20" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Response:

{
"data": [
{
"id": "doc_xyz789",
"templateId": "tmpl_abc123",
"status": "GENERATED",
"outputFormat": "PDF",
"createdAt": "2024-01-15T10:01:00Z"
}
],
"pagination": {
"page": 1,
"pageSize": 20,
"totalCount": 1
}
}

Error Handling

When generation fails, the document status will be FAILED and include error details:

{
"id": "doc_xyz789",
"status": "FAILED",
"error": {
"code": "MERGE_DATA_MISSING",
"message": "Required merge field 'customerName' not provided"
}
}

Common error codes:

CodeDescription
MERGE_DATA_MISSINGRequired template placeholder not provided
TEMPLATE_NOT_FOUNDTemplate ID does not exist or is archived
GENERATION_TIMEOUTDocument generation exceeded time limit
INVALID_FORMATUnsupported output format requested