Documents

Document Template Create

POST
/documents/template/create

Creates a document template: the file a document solution generates from, registered with where it lives and what format it is in. The template file itself is not uploaded here — this records a reference to a file that already exists, either in Doctavian Storage via documents-template-upload or on a connected drive.

Point at the file one of two ways, never both: urn together with loadMethod, or url on its own. fileFormat must agree with loadMethod — the Google formats gdoc, gsheet and gslide only work with GoogleDrive, and docx, xlsx and pptx only with Storage or OneDrive.

A template can be attached to document solutions in the same call by listing their ids in documentSolutions. That linking is best-effort: a solution that cannot be found is skipped rather than failing the request, so compare the returned list with what you sent.

A Storage template is subject to the upload retention window: files uploaded through documents-template-upload are removed once a document-generation request consumes them or after 24 hours, whichever comes first. The template record survives, but its urn stops resolving, so re-upload the file and update the urn before each generation run. Templates held on OneDrive or Google Drive are not affected.

Identifiers, ownership, folder and timestamps are all server-assigned and returned in the response; sending them has no effect, as does sending path, which exists only for display.

Authorization

AuthorizationBearer <token>

JWT token to authenticate the request.

In: header

X-Api-Key<token>

API key, sent as a request header.

In: header

Request Body

application/json

The DocumentTemplateModel payload to create. Server-managed fields (ids, timestamps, links, isDeleted) are ignored.

TypeScript Definitions

Use the request body type in TypeScript.

Body for creating a document template, following the standard request envelope: the resource under its own name alongside an optional externalContext.

Response Body

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/documents/template/create" \  -H "Content-Type: application/json" \  -d '{    "documentTemplate": {      "name": "Standard Invoice",      "description": "Company standard invoice layout.",      "title": "Invoice",      "urn": "9f86d081-884c-4d30-8934-9c1e6cbcb9f5",      "fileFormat": "docx",      "loadMethod": "Storage",      "documentSolutions": [        {          "id": "6ccb8ca9-2952-4dbf-a4b0-4a48bdeb1922"        }      ]    },    "externalContext": {      "id": "789"    }  }'
{  "result": {    "statusCode": 201,    "message": "Created",    "data": {      "documentTemplate": {        "id": "2b7c9e14-5a63-4f08-9d21-7c4e0b8a3f52",        "subscriptionId": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",        "ownerId": "1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d",        "lastModifiedUserId": "1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d",        "name": "Standard Invoice",        "description": "Company standard invoice layout.",        "title": "Invoice",        "urn": "9f86d081-884c-4d30-8934-9c1e6cbcb9f5",        "fileFormat": "docx",        "loadMethod": "Storage",        "path": "Templates / Standard Invoice.docx",        "documentSolutions": [          {            "id": "6ccb8ca9-2952-4dbf-a4b0-4a48bdeb1922",            "name": "Quarterly Invoicing",            "description": "Invoice run for quarterly billing."          }        ],        "ownerName": "Jane Doe",        "lastModifiedUserName": "Jane Doe",        "createdDate": "2026-09-18T12:15:53.000Z",        "lastModifiedDate": "2026-09-18T12:15:53.000Z"      }    }  },  "origin": "POST https://api.doctavian.com/v1/documents/template/create",  "dateTime": "2026-09-18T12:15:53.000Z",  "externalContext": {    "id": "789"  },  "userId": "1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d",  "operationId": "a0f31d9c6b4e4278ad15e9c73f082b64"}
{  "error": {    "statusCode": 400,    "message": "Name is required.",    "innerErrors": [      {        "code": "DATA_NAME_REQUIRED",        "message": "Name is required.",        "userMessage": "Give the template a name before saving it."      }    ]  },  "origin": "POST https://api.doctavian.com/v1/documents/template/create",  "dateTime": "2026-09-18T12:15:53.000Z",  "userId": "1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d",  "operationId": "a0f31d9c6b4e4278ad15e9c73f082b64"}
{  "error": {    "statusCode": 401,    "message": "The request could not be authenticated.",    "innerErrors": [      {        "code": "UNAUTHORIZED",        "message": "The request could not be authenticated.",        "userMessage": "Your session has expired or is invalid. Please sign in again."      }    ]  },  "origin": "POST https://api.doctavian.com/v1/documents/template/create",  "dateTime": "2026-09-18T12:15:53.000Z",  "userId": "1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d",  "operationId": "a0f31d9c6b4e4278ad15e9c73f082b64"}
{  "error": {    "statusCode": 403,    "message": "The caller is not authorized to perform this operation.",    "innerErrors": [      {        "code": "AUTHORIZATION_ERROR",        "message": "The caller is not authorized to perform this operation.",        "userMessage": "You do not have permission to do this. Contact your administrator."      }    ]  },  "origin": "POST https://api.doctavian.com/v1/documents/template/create",  "dateTime": "2026-09-18T12:15:53.000Z",  "userId": "1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d",  "operationId": "a0f31d9c6b4e4278ad15e9c73f082b64"}
{  "error": {    "statusCode": 500,    "message": "The template could not be created.",    "innerErrors": [      {        "code": "CREATE_DOCUMENT_TEMPLATE_ERROR",        "message": "The template could not be created.",        "userMessage": "Something went wrong. Please try again or contact support."      }    ]  },  "origin": "POST https://api.doctavian.com/v1/documents/template/create",  "dateTime": "2026-09-18T12:15:53.000Z",  "userId": "1a2b3c4d-5e6f-4a1b-8c2d-3e4f5a6b7c8d",  "operationId": "a0f31d9c6b4e4278ad15e9c73f082b64"}