This guide walks you through generating your first document. There are two ways to do it, and both are covered here:
POST /documents/document/generate with both. Nothing is saved apart from the generated file. This is the fastest way to see your template work, and the right choice when your own system decides what to generate and when.If you are new to the concepts, read Document Generation first.
Make sure you have:
Authorization bearer token and your API key (x-api-key) — see Authentication if not.docx, .xlsx or .pptx — with merge fields and elements already in place. See Document TemplatesFiles uploaded to Doctavian Storage are single-use and short-lived. An uploaded template or data file is held for 24 hours, and is removed sooner by the first generation that reads it — whether that generation succeeds or fails. Upload fresh files for every run.
Upload your template file as multipart/form-data. The upload accepts .docx, .xlsx and .pptx. You can send several files in one request — each gets its own storage id, returned in the order you sent them.
POST https://api.doctavian.com/v1/documents/template/upload
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: multipart/form-data
file: Standard Invoice.docxThe response returns a storage id for each file — this is what you'll pass as template.urn when generating:
{
"result": {
"data": {
"files": [
{ "id": "9f86d081-884c-4d30-8934-9c1e6cbcb9f5", "fileName": "Standard Invoice.docx" }
]
}
}
}Templates kept on OneDrive or Google Drive are not uploaded — you reference them directly in the generate request with
loadMethod: "OneDrive"or"GoogleDrive"and the drive's own file id. Google formats (gdoc,gsheet,gslide) can only be loaded from Google Drive. A macro-enabled.xlsmtemplate can't be uploaded here; keep it on OneDrive and reference it the same way.
Doctavian's data format is fixed: a root data object whose direct members are named lists of records. Every value inside a record is a string, already formatted for the locale you will generate in. A single record still goes in a list of one.
{
"data": {
"Invoice": [
{
"InvoiceNumber": "INV-2026-000123",
"IssueDate": "13/10/2026",
"Total": "1,250.50",
"LineItems": [
{ "Description": "Consulting", "Amount": "1,000.00" },
{ "Description": "Travel", "Amount": "250.50" }
]
}
],
"Customer": [
{ "Name": "Northwind Logistics", "AccountId": "0001008213" }
]
}
}You can send this either as one or more .json files in multipart/form-data, or as the raw request body with Content-Type: application/json:
POST https://api.doctavian.com/v1/documents/data/upload
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: application/json
{
"data": {
"Invoice": [ { "InvoiceNumber": "INV-2026-000123", "IssueDate": "13/10/2026", "Total": "1,250.50" } ],
"Customer": [ { "Name": "Northwind Logistics", "AccountId": "0001008213" } ]
}
}The response returns a storage id — this is what you'll pass as data.urn:
{
"result": {
"data": {
"files": [
{ "id": "a4f8c9d2-6b3e-4f1a-9c7d-2e5b8a1f4d6c", "fileName": "data$a4f8c9d2-6b3e-4f1a-9c7d-2e5b8a1f4d6c.json" }
]
}
}
}The upload checks only the outer shape (a root data object holding lists); everything inside the records is validated at generation time.
Each uploaded file is one data source with its own storage id. Uploading several
.jsonfiles in one multipart request prepares several data sources at once; they are not combined into one payload, and a generate request reads one of them.
With both ids in hand, generate in a single call. The body has three required sections and one optional one:
urn + loadMethod, or a direct url) and its fileFormaturn + loadMethod)name (without extension), fileFormat, deliveryMethod, path, locale and timeZonePOST https://api.doctavian.com/v1/documents/document/generate
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: application/json
{
"externalContext": { "orderId": "SO-2026-0042" },
"template": {
"urn": "9f86d081-884c-4d30-8934-9c1e6cbcb9f5",
"loadMethod": "Storage",
"fileFormat": "docx"
},
"data": {
"urn": "a4f8c9d2-6b3e-4f1a-9c7d-2e5b8a1f4d6c",
"loadMethod": "Storage"
},
"document": {
"name": "INV-2026-000123",
"fileFormat": "pdf",
"deliveryMethod": "Storage",
"path": "root",
"locale": "en-IE",
"timeZone": "Europe/Dublin"
}
}A few values need care:
| Field | What to send |
|---|---|
document.fileFormat | Must be one the template can produce — a docx template produces docx or pdf, for example. See Supported File Formats |
document.deliveryMethod | Storage (Doctavian Storage), OneDrive or GoogleDrive. Google formats can only go to Google Drive |
document.path | "root" is the root of Storage; "" is the root of OneDrive or Google Drive. These are real values, not placeholders. For a subfolder, append the relative path to that root value |
document.locale | A locale code from Locales and Timezones, such as en, de, en-IE or en-GB |
document.timeZone | An IANA time zone name, e.g. Europe/Dublin. Note the capital Z in the field name |
The call blocks until generation finishes. On success the response carries the generated file's id and echoes your externalContext:
{
"result": {
"statusCode": 201,
"data": {
"document": {
"deliveryMethod": "Storage",
"name": "INV-2026-000123",
"fileFormat": "pdf",
"urn": "c72f4a1e-9d3b-4c5f-8a6e-1b2c3d4e5f6a"
}
}
},
"consumption": [ { "dimension": "documents-generated", "value": 1 } ],
"externalContext": { "orderId": "SO-2026-0042" },
"operationId": "b5629806f22477783837ba2c1137f33d"
}result.data.document.urn identifies the generated file. For Storage it is a GUID; for OneDrive and Google Drive it is the drive's own file id.consumption is what was counted against your subscription.operationId is the reference to quote to support.When generation fails, nothing is written to the delivery target. Branch on error.innerErrors[].code — see Error Handling, and the API Reference for the full request and response schema and error codes.
The uploaded template and data are consumed by this call even if it fails. Upload them again before retrying.
For a Storage delivery, download the file by the urn from Step 3:
GET https://api.doctavian.com/v1/documents/document/c72f4a1e-9d3b-4c5f-8a6e-1b2c3d4e5f6a/download
Authorization: Bearer <token>
x-api-key: <api-key>The response body is the file itself — raw bytes, not JSON. Save it and open it to confirm your data landed correctly in the template.
Storage keeps a generated file for 24 hours; after that, download returns
404. Download it — or deliver to OneDrive or Google Drive instead — within that window.
For long-running or callback-driven work, send the same body to POST /documents/document/generate/async with an extra x-client-authorization header. The call returns an empty 200 as soon as the request is queued, and the result — the same envelope shown in Step 3, or an error envelope — is POSTed to your callback URL. See Handle Async Generation for the full flow, and Client Header for how to obtain the header value.
When you want Doctavian to keep the pieces — a named template, a Data Source, output settings, and a history of what was generated — register them as records and generate with a Document Request. Generation then runs in the background and you poll for the result. For how solutions, Configurations and requests fit together, see Document Solutions.
Upload the file as in Part 1, Step 1, then create a template record pointing at it. Locate the file with urn + loadMethod, or with url alone.
POST https://api.doctavian.com/v1/documents/template/create
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: application/json
{
"documentTemplate": {
"name": "Standard Invoice",
"description": "Company standard invoice layout.",
"urn": "9f86d081-884c-4d30-8934-9c1e6cbcb9f5",
"loadMethod": "Storage",
"fileFormat": "docx"
}
}The new record's id is at result.data.documentTemplate.id (here 2b7c9e14-5a63-4f08-9d21-7c4e0b8a3f52).
Upload the data as in Part 1, Step 2, then create a Data Source pointing at it.
POST https://api.doctavian.com/v1/documents/datasource/create
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: application/json
{
"dataSource": {
"name": "Customer invoice data",
"description": "Storage-based data for invoice generation",
"urn": "a4f8c9d2-6b3e-4f1a-9c7d-2e5b8a1f4d6c",
"loadMethod": "Storage"
}
}The new record's id is at result.data.dataSource.id (here 3f2504e0-4f89-41d3-9a0c-0305e82c3301).
Before going further you can check the Data Source reads correctly with POST /documents/datasource/{dataSourceId}/data/load — it returns the data exactly as generation would see it, without consuming a Storage file. See Set up Data Sources.
Attach the template and Data Source by id and define a Configuration in the same call with configurationDetails. For what a Configuration can set, see Document Solution Configurations.
POST https://api.doctavian.com/v1/documents/solution/create
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: application/json
{
"documentSolution": {
"name": "Quarterly Invoicing",
"description": "Invoice run for quarterly billing.",
"templates": [ { "id": "2b7c9e14-5a63-4f08-9d21-7c4e0b8a3f52" } ],
"dataSources": [ { "id": "3f2504e0-4f89-41d3-9a0c-0305e82c3301" } ],
"configurationDetails": [
{
"name": "Invoice - PDF to Storage",
"title": "Invoice",
"fileFormat": "pdf",
"deliveryMethod": "Storage",
"path": "root",
"locale": "en-IE",
"timeZone": "Europe/Dublin",
"isDefault": true
}
]
}
}The response returns the solution in full. Read the ids you need from it: result.data.documentSolution.id (here d290f1ee-6c54-4b01-90e6-d701748f0851) and the Configuration's id under configurationDetails[].id (here 7f1b2c3d-4e5f-4a6b-9c8d-0e1f2a3b4c5d).
Check that the returned templates and dataSources match what you sent: an id that can't be found is skipped, not rejected. See Creating a solution.
Name the template record, the Data Source record and the Configuration. Name the Configuration explicitly: the solution's default is not applied. See Key request fields.
POST https://api.doctavian.com/v1/documents/request/create
Authorization: Bearer <token>
x-api-key: <api-key>
Content-Type: application/json
{
"documentRequest": {
"name": "Invoice INV-2026-000123",
"title": "INV-2026-000123",
"documentTemplateId": "2b7c9e14-5a63-4f08-9d21-7c4e0b8a3f52",
"dataSourceId": "3f2504e0-4f89-41d3-9a0c-0305e82c3301",
"documentSolutionConfigurationId": "7f1b2c3d-4e5f-4a6b-9c8d-0e1f2a3b4c5d"
}
}The request is saved and returned at once with status New, and its id is at result.data.documentRequest.id (here b3f1c2d4-5e6a-4b7c-8d9e-0f1a2b3c4d5e). Generation starts in the background. Check the output settings in the response: they are the resolved values generation will use.
Poll GET /documents/request/{documentRequestId}/get every few seconds until status is Completed or Failed (see Status lifecycle):
GET https://api.doctavian.com/v1/documents/request/b3f1c2d4-5e6a-4b7c-8d9e-0f1a2b3c4d5e/get
Authorization: Bearer <token>
x-api-key: <api-key>On Completed, the request carries documentId:
{
"result": {
"data": {
"documentRequest": {
"id": "b3f1c2d4-5e6a-4b7c-8d9e-0f1a2b3c4d5e",
"documentId": "810980b2-319e-4ea3-9878-8b54b1dc5da9",
"status": "Completed",
...
}
}
}
}On Failed, errorMessage says why. A failed request is not retried: fix the cause and create a new one. The most common cause is FILE_MISSING_FROM_STORAGE — the template or data file was already consumed or expired.
documentId names the document record, not the file. Read the record to get the file's urn:
GET https://api.doctavian.com/v1/documents/document/810980b2-319e-4ea3-9878-8b54b1dc5da9/get
Authorization: Bearer <token>
x-api-key: <api-key>{
"result": {
"data": {
"document": {
"id": "810980b2-319e-4ea3-9878-8b54b1dc5da9",
"urn": "19a9cf71-893a-4ed1-b73d-8ec034d698e3",
"deliveryMethod": "Storage",
...
}
}
}
}Then download by the record's urn, exactly as in Part 1, Step 4:
GET https://api.doctavian.com/v1/documents/document/19a9cf71-893a-4ed1-b73d-8ec034d698e3/download
Authorization: Bearer <token>
x-api-key: <api-key>Don't mix up the two ids.
documentId(the record'sid) is whatdocument/{documentId}/getand/deletetake; the record'surnis what/downloadtakes. See Storage and File IDs.
The Storage files behind the template and Data Source were consumed by this generation. Before the next run, upload fresh files and point the records at the new ids with PUT /documents/template/{documentTemplateId}/update and PUT /documents/datasource/{dataSourceId}/update. Both are full replacements — send every field you want to keep. Templates and data kept on OneDrive or Google Drive are not consumed and need no update.
New to Completed, and its document record and file