Document Generate Async
Initiates the same document generation as documents-document-generate — specify a template, supply the data to populate it, and configure the output format, storage location, and delivery method — but asynchronously.
This endpoint returns 201 with an empty body as soon as the request is accepted and queued. That response only acknowledges receipt; it does not mean the document was generated, and it carries no document metadata.
The result arrives at your callback URL, not in the response to this call. Once generation finishes, Doctavian sends a POST to the URL formed by joining the iss and dest claims of the X-Client-Authorization token supplied on this request, authenticating itself with that token's sub claim. Your endpoint should return any success status to acknowledge receipt.
The callback body is the generation outcome, in one of two shapes. On success it is the DocumentGenerateResponse envelope — the identical shape the synchronous documents-document-generate operation returns as its 201 body, carrying result.data.document (the generated document's deliveryMethod, name, fileFormat, urn, and, for drive deliveries, uri and the sharing links) plus consumption. On failure it is the standard ErrorResponse error envelope, with the cause in error.innerErrors[]. Both shapes carry the same externalContext, origin, dateTime, userId, and operationId metadata; result and consumption appear only on success, error only on failure. Correlate a callback back to the request that produced it through externalContext, which is echoed back unchanged from the request body.
A 400 from this endpoint means the request was rejected before being queued, so no callback follows it.
Use this endpoint instead of the synchronous variant when generation is expected to take long enough that you don't want the calling request to block, or when your integration is callback-driven.
JWT token to authenticate the request.
In: header
API key, sent as a request header.
In: header
Header Parameters
Request Body
application/json
The request has three mandatory top-level sections — template, data, and document — plus an optional externalContext, an arbitrary JSON object echoed back unchanged so you can match a response to the request that produced it.
template identifies the file to generate from. Locate it either by url alone, or by urn + loadMethod together; supplying neither pair means the template can't be resolved and the request fails with TEMPLATE_NOT_FOUND. template.relatedItems lists additional templates the primary template pulls in via an Include directive, each matched to that directive by its name. template.options, and each related item's own options, carry load settings for the template file format.
data identifies the source of the values consumed by the template's merge fields, expressions, and other data-driven elements. urn and loadMethod are both always mandatory — unlike template, there is no url alternative. variables layers static or computed values on top of that source; embedded writes custom metadata into the output file's properties rather than its visible content.
document configures the output. timezone, locale, name, fileFormat, deliveryMethod, and path are all mandatory. document.options carries save settings for the output format, Google-engine tuning in googleGenerate, and sharing settings in onedrive or googleDrive — whichever matches deliveryMethod; the other is ignored.
The three sections constrain each other. These combinations are validated, and an invalid one fails the request rather than producing a document:
template.fileFormatmust be consistent withtemplate.loadMethod.gdoc,gsheet, andgslideare Google Workspace formats, loadable only whenloadMethodisGoogleDrive;docx,xlsx, andpptxare Microsoft formats, loadable only fromStorageorOneDrive.document.fileFormatmust matchtemplate.fileFormat, with two exceptions:pdfcan be produced from any template, andcsvcan be produced only from anxlsxtemplate.document.deliveryMethodis constrained bydocument.fileFormat. Google formats can only be delivered toGoogleDrive; Microsoft formats toStorageorOneDrive;pdfandcsvto any of the three.document.pathis relative to the root of the target selected bydeliveryMethod, and that root is spelled differently per target:"root"forStorage,""forOneDriveandGoogleDrive. Concatenate any subfolder onto that root rather than replacing it.- Inside
template.optionsanddocument.options, only the property matching the relevant format is read —docxLoadOptionsfor adocxtemplate,pdfSaveOptionsforpdfoutput, and so on. The Google formats don't pass through GemBox and have no load or save options.
TypeScript Definitions
Use the request body type in TypeScript.
Request body for generating a document from a template. Defines which template to use, what data populates it, and how the resulting file is formatted and delivered.
Response Body
application/json
curl -X POST "https://example.com/documents/document/generate/async" \ -H "X-Client-Authorization: eyJhbGciOiJIUzI1NiJ9.example-client-callback-token" \ -H "Content-Type: application/json" \ -d '{ "externalContext": { "actionRequestId": "req-2026-0007421" }, "template": { "name": "Standard Invoice", "urn": "9f86d081-884c-4d30-8934-9c1e6cbcb9f5", "fileFormat": "docx", "loadMethod": "Storage", "options": { "docxLoadOptions": "{ \\"PreserveUnsupportedFeatures\\": true }" }, "relatedItems": [ { "name": "Invoice Terms Addendum", "urn": "4b1e2f3a-5c6d-47e8-9a0b-1c2d3e4f5a6b", "fileFormat": "docx", "loadMethod": "Storage" } ] }, "data": { "loadMethod": "Storage", "urn": "a4f8c9d2-6b3e-4f1a-9c7d-2e5b8a1f4d6c", "variables": [ { "name": "createdDate", "value": "{!$now()}", "type": "fieldExpression" }, { "name": "requestId", "value": "{!requestId}", "type": "graphql" }, { "name": "customerName", "value": "Jane Doe", "type": "global" } ], "query": "{\\"query\\":\\"{Account {Name Description Owner.Username Id Opportunities {StageName OpportunityLineItems {Name}} Contacts {Id}}}\\"}", "embedded": "{ \\"contractId\\": \\"12345\\" }" }, "document": { "timezone": "(GMT+00:00) Greenwich Mean Time (Europe/Dublin)", "locale": "en_IE_EURO", "name": "Q3 Sales Report", "fileFormat": "docx", "deliveryMethod": "Storage", "path": "root", "options": { "pdfSaveOptions": "{ \\"ConformanceLevel\\": \\"PdfA3a\\", \\"Version\\": \\"PDF_1_7\\", \\"ImageDpi\\": 750, \\"SelectionType\\": \\"EntireFile\\" }", "docxSaveOptions": "{}", "onedrive": { "viewAnonymous": true, "editAnonymous": true, "editUsers": [ "user@example.com" ], "viewUsers": [ "user@example.com" ] }, "googleDrive": { "viewAnonymous": true, "editAnonymous": true, "editUsers": [ "user@example.com" ], "viewUsers": [ "user@example.com" ] }, "googleGenerate": { "nativeMergeEnabled": true, "nativeImageMergeEnabled": true } } } }'{ "error": { "statusCode": 400, "message": "Bad Request", "innerErrors": [ { "code": "X_CLIENT_AUTH_ERROR", "message": "header is missing for async operations", "userMessage": "This request can't be accepted without a callback authorization header." } ] }, "externalContext": { "actionRequestId": "req-2026-0007421" }, "origin": "POST https://api.doctavian.com/v1/documents/document/generate/async", "dateTime": "2026-07-14T09:30:00.000Z", "userId": "1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d", "operationId": "38a1de72cef5aba1c0b26dd712239827"}