API ReferenceDocuments

Documents API

Generate PDF documents from your templates.

Endpoint

POST /api/v1/{org_slug}/templates/{endpoint_path}/documents

Parameters

ParameterTypeRequiredDescription
org_slugstringYesYour organization identifier
endpoint_pathstringYesTemplate endpoint configured in dashboard

Request Headers

HeaderRequiredDescription
AuthorizationYesBearer token with your API key
Content-TypeYesMust be application/json
PreferNoUse respond-async for async mode

Request Body

Send your template data as JSON. The required fields depend on your template configuration.

Basic Example

{
  "invoice_number": "INV-001",
  "customer_name": "Acme Corp",
  "amount": 1250.00,
  "items": [
    { "name": "Widget", "quantity": 5, "price": 250.00 }
  ]
}

Special Fields

FieldTypeDescription
isTestbooleanEnable test mode (watermarked PDF)
webhookobjectLegacy webhook configuration

Response Formats

Synchronous Response

Returns the PDF binary directly:

HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Length: 123456
X-Request-ID: req_abc123

[PDF binary data]

Asynchronous Response

When using Prefer: respond-async header:

{
  "request_id": "req_abc123xyz",
  "status": "queued",
  "created_at": "2024-01-01T00:00:00Z"
}

Code Examples

# Synchronous
curl -X POST https://api.doczap.app/api/v1/acme/templates/invoice/documents \
  -H "Authorization: Bearer sk_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "invoice_number": "INV-001",
    "customer_name": "Acme Corp",
    "amount": 1250.00
  }' \
  -o invoice.pdf
 
# Asynchronous
curl -X POST https://api.doczap.app/api/v1/acme/templates/invoice/documents \
  -H "Authorization: Bearer sk_live_your_key" \
  -H "Content-Type: application/json" \
  -H "Prefer: respond-async" \
  -d '{
    "invoice_number": "INV-001",
    "customer_name": "Acme Corp",
    "amount": 1250.00
  }'

Template Placeholders

Templates use double curly braces for placeholders:

  • {{invoice_number}} - Simple field replacement
  • {{customer.name}} - Access nested objects
  • {{items.0.price}} - Access array elements

Supported Syntax

SyntaxExampleDescription
Simple{{name}}Direct field replacement
Nested{{user.email}}Access nested objects
Array{{items.0.name}}Access array elements

Placeholders are HTML-escaped by default for security. Unmatched placeholders remain in the output.

Page Configuration

Configure PDF output in your template settings:

OptionValuesDefaultDescription
pageSizea3, a4, a5, letter, legal, tabloida4Paper size
orientationportrait, landscapeportraitPage orientation

Limitations

LimitValue
Request size1 MB
Timeout (sync)30 seconds
PDF size50 MB
Concurrent requests10 per API key

Error Handling

Common errors and solutions:

StatusErrorSolution
400invalid_template_dataCheck required fields
401unauthorizedVerify API key
404template_not_foundCheck endpoint path
413payload_too_largeReduce request size
422validation_failedFix data format
429rate_limit_exceededImplement backoff
500internal_errorRetry with backoff

Example error response:

{
  "error": {
    "message": "Validation failed: amount is required",
    "type": "validation_error",
    "code": "missing_required_field",
    "field": "amount"
  }
}