Generate
Generate a document with one request: send a document definition as the body, as you would save it in a file, or name a
stored template. Beside the definition you may send data, which its $data tokens and source bindings read, and
delivery, which mails the document. Append the format to the path; any value other than pdf or docx is refused
with 400.
Machine-readable specs:
- OpenAPI Spec (JSON) — import into your API client or gateway
- Document Definition JSON Schema — for IDE autocomplete and payload validation
POST /documents/generate/{format}
Endpoint
POST /v1/{tenantId}/documents/generate/{format}
format | Output |
|---|---|
pdf | PDF document (the same path without a format writes a PDF) |
docx | Word document |
Headers
| Header | Value | Required |
|---|---|---|
Authorization | Bearer YOUR_ACCESS_TOKEN | Yes |
Content-Type | application/json | Yes |
Idempotency-Key | A key of your own, such as "8e03978e-40d5-43e8-bc93-6894a57f9324": see Retrying safely | No |
YOUR_ACCESS_TOKEN is the access token you get by exchanging your API key's Client ID and secret; see Authentication.
Path parameters
| Parameter | Type | Description |
|---|---|---|
tenantId | string | Your tenant identifier |
Request body
The body is a document definition, as the Document Definition describes it: a file you validate against the schema posts unchanged. Beside its root, the request may carry its own members.
| Member | Type | Description |
|---|---|---|
document | object | The document to generate. Send it, templateId or example |
templateId | string (GUID) | A stored template to generate in place of a definition sent here |
example | string | A published example to generate in place of a definition sent here, by its slug (certificates/professional-certification) |
data | object | The values the definition's $data tokens read, by name. Each replaces the definition's own params default of that name. Absent, null or {}, the definition is rendered with its defaults |
delivery | object | A reference of your own returned on every event, and the document mailed to its readers; see Delivery. Absent, a document generated with an API key goes to your organization's fixed recipients when it turned automatic delivery on |
A definition and its data:
{
"document": {
"metadata": { "title": "Invoice $data.invoice.number" },
"content": [
{ "h1": "Invoice $data.invoice.number" },
{ "p": "Billed to $data.client.companyName, $data.client.city" },
{ "p": "Total due: $data.invoice.grandTotal" }
]
},
"data": {
"client": { "companyName": "Meridian Logistics", "city": "Austin, TX" },
"invoice": { "number": "INV-2026-0007", "grandTotal": "$19,000" }
}
}
A stored template and its data:
{
"templateId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"data": {
"client": {
"companyName": "Meridian Logistics",
"contactName": "Sarah Mitchell",
"address": "12 Harbor Road",
"city": "Austin, TX"
},
"document": {
"title": "Professional Services Invoice",
"date": "March 30, 2026"
},
"lineItems": [
{ "service": "Platform setup", "hours": "80", "rate": "$150", "total": "$12,000" },
{ "service": "API integration", "hours": "40", "rate": "$175", "total": "$7,000" }
],
"invoice": {
"grandTotal": "$19,000"
},
"paymentTerms": [
"Wire transfer to ShipForge Ltd account",
"Net 30 days from invoice date"
]
}
}
A published example and its data, as the Playground sends the example it opened until you change it:
{
"example": "certificates/professional-certification",
"data": { "recipient": { "fullName": "Alexandra Brennan-Cole" } }
}
More than one of a definition, a templateId and an example, or none of them, is answered 400 with
VALIDATION_ERROR, as is a member of the wrong kind; an example the catalog does not hold is answered 404 with
NOT_FOUND. The refusals are listed under the response below.
Response
Success (200 OK)
Returns the generated document's metadata with a download URL.
{
"status": "succeeded",
"triggeredAt": "2026-10-17T14:30:21.402Z",
"completedAt": "2026-10-17T14:30:22.118Z",
"documentId": "d4e5f6a7b8c90123456789abcdef0123",
"fileName": "docpayload_v1-d4e5f6a7b8c90123456789abcdef0123.pdf",
"downloadUrl": "https://api.docpayload.com/v1/{tenantId}/assets/docs/docpayload_v1-d4e5f6a7b8c90123456789abcdef0123.pdf",
"expiresAt": null,
"fileSizeBytes": 31744,
"sizeClass": "small",
"charge": 0.05,
"message": "PDF generated and uploaded successfully.",
"errorCodes": [],
"problems": []
}
| Field | Description |
|---|---|
status | succeeded, or failed with a 500 |
fileName | The stored file; its extension follows the requested format (.pdf or .docx) |
downloadUrl | Where to fetch the file, with the same bearer token |
expiresAt | Always null: a generated document does not expire |
sizeClass | The size the document is priced by: small, standard or large |
charge | What this generation was charged, in the plan's currency; null on a plan that charges none per document, and on a plan priced per user, where the month's invoice settles the documents included and any beyond them |
errorCodes | What the document asked for and did not get; empty when it got everything. Check it before you hand the file on: see below |
problems | The same, each with whose move it is and the reason: see below. They are kept with the document: GET /documents/{documentId}/problems returns them later |
A request with delivery is also answered with delivery: each email queued, as
Delivery shows.
errorCodes
A document can be generated and still lack something it asked for: an image that was not found, a token with no value. The document is written, stored and counted, and errorCodes names what is missing, each code once. It is
empty when the document got everything it asked for, so check it before you hand a document on.
| Code | The document lacks |
|---|---|
IMAGE_NOT_LOADED | an image: it was not found, could not be read or could not be decoded |
FONT_NOT_LOADED | a font file it declares: it was not found or could not be read, and its text is set in another face |
GLYPH_NOT_DRAWN | characters: no available font covers them (neither a font the document declares nor one the engine ships), so they are left out of the page. The problem's message names each one; declare a font that covers them |
SVG_NOT_LOADED | an svg file: it was not found or could not be read |
ATTACHMENT_NOT_EMBEDDED | an attachment: the file was not found or could not be read |
UNRESOLVED_TOKEN | a value: a $data or $global token had none, and its own spelling is on the page |
CONFORMANCE_WITHHELD | a claim: the file does not meet a PDF/A, PDF/UA or Factur-X claim it would carry, a signature level it asked for (a timestamp authority that gave no timestamp leaves the signature without one), or the DOCX class it named, so the claim is left out (Conformance). An encrypted document is simply not archival, and carries no code for it |
CONTENT_ERROR | something else the definition asked for |
problems
The same, each with the reason and whose move it is, so you know whether to change the document or simply try again. A
code appears in errorCodes once; it can appear in problems once per thing missing.
"problems": [
{
"code": "CONFORMANCE_WITHHELD",
"cause": "service",
"message": "PDF/A withheld: ISO 19005-4 6.5.2: the signature carries no timestamp, neither its own nor a document timestamp (the reason is said above), and PDF/A-4 requires one (a PAdES-T profile); render again once the authority answers"
}
]
cause | Whose move it is |
|---|---|
document | Yours: the message names the key to set, the file to supply or the value to change |
service | An outside service the document named, such as a timestamp authority, did not deliver. The document is right as written: generate it again once the service answers |
platform | Ours: nothing in the document causes it, and nothing in it will change it |
A message can quote your document, so it is returned to you, kept with the document and sent to your own webhook endpoints, and never written to a log.
Error (400 Bad Request): the request is refused
A request with both a definition and a templateId, with neither, or with a member of the wrong kind is answered with
the member at fault. Nothing is generated, stored or billed.
{
"type": "https://docs.docpayload.com/api-reference/errors#validation-error",
"title": "A request parameter is not valid",
"status": 400,
"detail": "Send a definition or a templateId, not both.",
"code": "VALIDATION_ERROR",
"target": "templateId"
}
Error (400 Bad Request): the definition is refused
A definition sent or a stored template is judged as every definition is, with nothing stored or billed: a definition
the schema refuses is answered with its code and the place as target, a body that is not JSON INVALID_JSON, a retired word
RETIRED, and a use naming a component the tenant does not have UNRESOLVED_COMPONENT. See
Errors.
{
"type": "https://docs.docpayload.com/api-reference/errors#schema",
"title": "The definition is not on the schema",
"status": 400,
"detail": "\"tabel\" is not in this schema; this object takes: source, break, p, th, td, h1, ...",
"code": "SCHEMA",
"target": "document.content.0"
}
Error (400 Bad Request): the signature could not be applied
Returned when the document asks for a signature and it cannot be applied. A signed document that is not signed is not the document you asked for, so nothing is generated, stored or counted.
{
"type": "https://docs.docpayload.com/api-reference/errors#signature-not-applied",
"title": "The signature the document asks for cannot be applied",
"status": 400,
"detail": "The signature could not be applied. Check the document's certificate and its password. Nothing was generated or billed.",
"instance": "/v1/{tenantId}/documents/generate/pdf",
"code": "SIGNATURE_NOT_APPLIED",
"requestId": "4bf92f3577b34da6a3ce929d0e0e4736",
"isRetryable": false
}
Error (404 Not Found)
Returned when the templateId does not exist or does not belong to your tenant.
{
"type": "https://docs.docpayload.com/api-reference/errors#not-found",
"title": "The resource does not exist",
"status": 404,
"detail": "Template 'a1b2c3d4-e5f6-7890-abcd-ef1234567890' not found.",
"code": "NOT_FOUND"
}
Error (402 Payment Required)
MONTHLY_ALLOWANCE_REACHED when the plan's documents for the month are used up, ACCOUNT_SUSPENDED when an invoice is
unpaid. Nothing is generated.
A body without Content-Type: application/json is answered 400 with INVALID_CONTENT_TYPE,
a body over 1 MB 413, and a format other than pdf or docx 400. A render that fails is answered 500 with the
response above and "status": "failed"; nothing is stored or billed. Every refusal is the one Problem Details body
described under Errors.
Examples
A definition saved in a file, posted as it is:
curl -X POST https://api.docpayload.com/v1/{tenantId}/documents/generate/pdf \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
--data @invoice.json
A stored template with its data, written as a Word document:
curl -X POST https://api.docpayload.com/v1/{tenantId}/documents/generate/docx \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"templateId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"data": {
"client": {
"companyName": "Meridian Logistics"
},
"document": {
"title": "Delivery Receipt"
}
}
}'
Retrying safely
A request that timed out or lost its connection may have generated the document, and billed it, before its answer was
lost. Send an Idempotency-Key with it, a key of your own, and sending the same request again with the same key is
answered as the first was: the same document, generated and billed once.
curl -X POST "https://api.docpayload.com/v1/{tenantId}/documents/generate/pdf" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-H 'Idempotency-Key: "8e03978e-40d5-43e8-bc93-6894a57f9324"' \
-d @invoice.json
- The key is a quoted string, as the Idempotency-Key header
defines it: 1 to 255 printable ASCII characters between double quotes. A fresh UUID per document is the simplest.
Anything else is refused with
400 IDEMPOTENCY_KEY_INVALID. - The same request is the same method, path and body, byte for byte. Sent with a key already used for a request
of another path or body, it is refused with
422 IDEMPOTENCY_KEY_REUSED. A key names one document: send a new key for a new one. - While the first request still runs, the same request is answered
409 IDEMPOTENCY_KEY_IN_FLIGHT: wait a moment and send it again. - A key is kept for 24 hours from the answer, within your organization only. A request whose answer was not a success (a refusal, an error) keeps nothing: correct it, or wait for the service, and send it again with the same key.
- Without the header, every request is generated, as before.
Data resolution
When this endpoint is called:
- The definition is the body without its
dataanddelivery, or the stored template named bytemplateId. - It is judged against the schema, and every
useis looked up in the tenant's components. A refusal is a400, and nothing is stored or billed. - The components are composed into the document, and
databinds every$datatoken, everysourceon a table or a list, and the components'params, over the definition's ownparamsdefaults. The$globaltokens (date, title, page numbers) are resolved too. - The document is rendered to the requested format, PDF or DOCX, stored, and billed.
What is resolved
| Feature | Example | Description |
|---|---|---|
| Scalar text | $data.client.name | Replaced with the value at the given path |
| Nested paths | $data.client.address.city | Dot-separated traversal of nested objects |
| Inside formatting | [b]$data.total[/b] | Ref resolved, then formatting applied |
| Form defaults | '$data.applicant.email' | Pre-fills editable form fields |
| Table rows | "source": "$data.items" | Array items become table rows |
| List items | "source": "$data.notes" | Array items become list items |
| Unresolved refs | $data.missing.key | Drawn as written, and named by UNRESOLVED_TOKEN in errorCodes |
Downloading the document
Use the downloadUrl from the response to fetch the generated document:
curl -X GET "https://api.docpayload.com/v1/{tenantId}/assets/docs/docpayload_v1-d4e5f6a7b8c90123456789abcdef0123.pdf" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-o invoice.pdf