Skip to main content

Templates API

Manage reusable document templates. Templates store document definitions that can be combined with data at generation time to produce personalized PDF or DOCX documents.

All endpoints require authentication and are scoped to a tenant.


GET /templates​

List the tenant's templates, the current revision of each, ordered by name, a page at a time.

Endpoint​

GET /v1/{tenantId}/templates
Query parameterDefaultDescription
maxpagesize200The most templates a page holds, at most 500. A page may hold fewer
cursorWhere the page starts, as nextLink carries it. Absent for the first page

While there are more, nextLink is the URL of the next page: follow it as it is, until a page comes without one. A template renamed while you page through may be answered twice or not at all.

Response​

Success (200 OK)

{
"value": [
{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"parentId": null,
"tenantId": "f1e2d3c4-b5a6-7890-1234-567890abcdef",
"name": "Shipping Invoice",
"content": "{ \"document\": { ... } }",
"data": "{ \"client\": { ... } }",
"createdAt": "2026-03-15T10:00:00Z",
"createdBy": "laura.bennett@shipforge.io",
"owner": "laura.bennett@shipforge.io",
"updatedAt": "2026-03-28T14:30:00Z",
"revision": "rev-20260328T143000"
}
],
"nextLink": "https://api.docpayload.com/v1/{tenantId}/templates?maxpagesize=200&cursor=b3BhcXVlLXBhZ2UtdG9rZW4..."
}

GET /templates/names​

List the tenant's templates without their content or data: the same templates as GET /templates, the current revision of each, in the same order (by name), all in one page.

Endpoint​

GET /v1/{tenantId}/templates/names

Response​

Success (200 OK)

Each entry carries the folder the template sits in (path, null at the root), the name a use resolves it by (componentName, its metadata.name, null when it declares none), and its current revision: the label (revision), when it was written (updatedAt) and by whom (createdBy, named as in GET /templates).

{
"value": [
{
"id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"name": "Line items",
"path": "invoices/parts",
"componentName": "line-items",
"revision": "rev-20260402T091500",
"updatedAt": "2026-04-02T09:15:00Z",
"createdBy": "Laura Bennett"
},
{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "Shipping Invoice",
"path": "invoices",
"componentName": null,
"revision": "rev-20260328T143000",
"updatedAt": "2026-03-28T14:30:00Z",
"createdBy": "Laura Bennett"
}
]
}

POST /templates​

Create a new template.

Endpoint​

POST /v1/{tenantId}/templates

Request body​

FieldTypeRequiredDescription
namestringYesTemplate name (max 100 characters)
contentstringYesJSON document definition as a string
datastringNoSample data JSON for preview/testing
pathstringNoThe folder the template is filed in (up to 500 characters)
parentIdstring (GUID)NoParent template ID for revision chains

The author and the owner are not sent: a new template is signed with the caller, whose identity the response's createdBy and owner carry.

{
"name": "Shipping Invoice",
"content": "{\"document\":{\"content\":[{\"p\":\"Invoice for $data.client.name\"}]}}",
"data": "{\"client\":{\"name\":\"Test Corp\"}}"
}

Response​

Success (201 Created)

Returns the created template with a generated id, revision, and timestamps.

{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"parentId": null,
"tenantId": "f1e2d3c4-b5a6-7890-1234-567890abcdef",
"name": "Shipping Invoice",
"content": "{\"document\":{\"content\":[{\"p\":\"Invoice for $data.client.name\"}]}}",
"data": "{\"client\":{\"name\":\"Test Corp\"}}",
"createdAt": "2026-03-30T14:30:00Z",
"createdBy": "laura.bennett@shipforge.io",
"owner": "laura.bennett@shipforge.io",
"updatedAt": "2026-03-30T14:30:00Z",
"revision": "rev-20260330T143000"
}

GET /templates/{id}​

Get a single template by ID.

Endpoint​

GET /v1/{tenantId}/templates/{id}

Path parameters​

ParameterTypeDescription
idstring (GUID)Template identifier

Response​

Success (200 OK)

Returns the full template object.

Error (404 Not Found)

Returned when no template with the given ID exists for this tenant.


PUT /templates/{id}​

Save an existing template. A change to its content or data becomes its next revision, after the current one, whichever revision {id} names; a save that changes neither adds no revision. A new name renames every revision. Moving a template to another folder is done by moving it, not by saving it.

Endpoint​

PUT /v1/{tenantId}/templates/{id}

Request body​

FieldTypeRequiredDescription
idstring (GUID)YesMust match the {id} path parameter
namestringNoUpdated template name; left out, the template keeps its own
contentstringYesUpdated document definition
datastringNoUpdated sample data

The author and the owner are not sent: the next revision is signed with the caller, and the template keeps its owner.

{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "Shipping Invoice v2",
"content": "{\"document\":{\"content\":[{\"p\":\"Updated invoice for $data.client.name\"}]}}",
"data": "{\"client\":{\"name\":\"Test Corp\"}}"
}

Response​

Success (204 No Content)

The template was updated successfully.

Error (400 Bad Request)

Returned when the id in the body does not match the path parameter, when the name holds a slash, a backslash or a line break, or when the body names another folder than the template's.

Error (404 Not Found)

Returned when no template with the given ID exists.

Error (409 Conflict)

Returned when another template already has the new name, or when another save of the same template landed at the same moment. Reload the template and save again.


DELETE /templates/{id}​

Delete a template. Needs the document:delete scope.

Endpoint​

DELETE /v1/{tenantId}/templates/{id}

Path parameters​

ParameterTypeDescription
idstring (GUID)Template identifier

Response​

Success (204 No Content)

The template was deleted, or was not there to delete. With If-Match, a template that is gone is 412.


Template revisions​

Templates support versioning through revisions. Each save that changes the content or the data creates a new revision linked to its parent.

POST /templates/{templateId}/revisions​

Create a new revision of a template, with the same body as PUT. Answered 201 Created with the new revision, or 200 OK with {"message": "No changes detected.", "skipped": true} when neither the content nor the data changed.

POST /v1/{tenantId}/templates/{templateId}/revisions

GET /templates/{templateId}/revisions​

List all revisions of a template in value, ordered by most recent first.

GET /v1/{tenantId}/templates/{templateId}/revisions

DELETE /templates/{templateId}/revisions/{revisionId}​

Delete a specific revision.

DELETE /v1/{tenantId}/templates/{templateId}/revisions/{revisionId}

POST /templates/{templateId}/revisions/{revisionId}:revert​

Revert a template to a previous revision. This creates a new revision with the content from the specified historical revision.

POST /v1/{tenantId}/templates/{templateId}/revisions/{revisionId}:revert

Other template endpoints​

These are part of the same API and its OpenAPI description:

EndpointDoes
DELETE /v1/{tenantId}/templatesDeletes up to 200 templates by id, body { "ids": [...] } (scope document:delete)
POST /v1/{tenantId}/templates/{id}:renameRenames every revision of a template
POST /v1/{tenantId}/templates:forkCopies a community template into the tenant
GET /v1/{tenantId}/templates/{id}/upstreamSays whether the template a fork came from has changed since
POST /v1/{tenantId}/templates/{id}:pullTakes the upstream template's latest content as a new revision
GET, POST, DELETE /v1/{tenantId}/templates/foldersLists (in value), creates and deletes template folders
POST /v1/{tenantId}/templates/folders:renameRenames a folder
POST /v1/{tenantId}/templates:moveMoves templates to another folder