
## Update template

`PATCH /v1/doc-templates/:id`

Partially updates a document template, including replacing its .docx file. Pass only the fields you are changing, flat at the root of the JSON — all other values are preserved.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `id` (path) | number | yes | Template identifier |

## Request fields (body)

| Field | Type | Description |
|------|-----|---------|
| `name` | string | Template name |
| `numeratorId` | number | ID of the numerator that assigns sequential numbers to documents |
| `region` | string | Template region code, for example `uk` or `de` |
| `code` | string | System code of the template used to reference it from application code |
| `active` | string | Template availability: `Y` — enabled, `N` — disabled |
| `withStamps` | string | Facsimile and stamp printing: `Y` — added, `N` — not added |
| `sort` | number | Template order in the list: the lower the value, the higher the template appears |
| `users` | array | Identifiers of employees who have access to the template. List: `GET /v1/users` |
| `file` | string | New `.docx` file content as a base64 string. Replaces the template file; the template `id` stays the same |

The file is replaced only through `file`. The `fileId` field, which takes a Drive object ID when [creating a template](/docs/entities/doc-templates/create), is not applied on update.

Read-only fields (`id`, `moduleId`, `createdBy`, `updatedBy`, `createTime`, `updateTime`, `isDeleted`, `download`, `downloadMachine`, `providers`, `isDefault`, `productsTableVariant`) are not accepted in the request body: a request carrying any of them is refused with `400 READONLY_FIELD`. The owner module `moduleId` is assigned by the platform.

## Examples

### curl — personal key

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/doc-templates/209" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Contract template (updated)"
  }'
```

### curl — OAuth application

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/doc-templates/209" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Contract template (updated)"
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/doc-templates/209', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'Contract template (updated)',
  }),
})

const { success, data } = await res.json()
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/doc-templates/209', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'Contract template (updated)',
  }),
})

const { success, data } = await res.json()
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | object | The full updated template |
| `data.id` | number | Template identifier |
| `data.name` | string | Name |
| `data.region` | string | Region |
| `data.code` | string \| null | System code of the template |
| `data.active` | string | Availability: `Y` / `N` |
| `data.moduleId` | string | Source module of the template |
| `data.numeratorId` | number | Numerator identifier |
| `data.withStamps` | string | Stamps and signatures: `Y` / `N` |
| `data.sort` | number | Order in the list |
| `data.users` | object | Map of employee identifiers with access to the template |
| `data.providers` | object | Template data providers |
| `data.isDeleted` | boolean | Whether the template is marked as deleted |
| `data.createTime` | string | Creation date (ISO 8601) |
| `data.updateTime` | string | Last update date (ISO 8601) |
| `data.download` | string | Document download URL |
| `data.downloadMachine` | string | Vibe API URL; requires X-Api-Key with documentgenerator scope |

Full template field schema — [Template fields](./fields.md).

## Response example

```json
{
  "success": true,
  "data": {
    "id": 209,
    "name": "Contract template (updated)",
    "region": "uk",
    "code": null,
    "download": "/bitrix/services/main/ajax.php?action=documentgenerator.api.template.download&SITE_ID=s1&id=209&ts=0",
    "active": "Y",
    "moduleId": "rest",
    "numeratorId": 1,
    "withStamps": "N",
    "providers": {
      "bitrix\\documentgenerator\\dataprovider\\rest": "bitrix\\documentgenerator\\dataprovider\\rest"
    },
    "users": {
      "U1": "U1"
    },
    "isDeleted": false,
    "sort": 500,
    "createTime": "2026-05-12T09:03:38.000Z",
    "updateTime": "2026-05-25T10:00:11.000Z",
    "downloadMachine": "https://vibecode.bitrix24.com/v1/doc-templates/209/download"
  }
}
```

## Error response example

404 — template not found:

```json
{
  "success": false,
  "error": {
    "code": "ENTITY_NOT_FOUND",
    "message": "Template was not found."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `READONLY_FIELD` | The body carried a read-only field — for example the owner module `moduleId`, which the platform assigns. The check runs before the call to Bitrix24, so this refusal arrives even for a non-existent `id` |
| 404 | `ENTITY_NOT_FOUND` | No template with the given `id` (message "Template was not found.") |
| 422 | `BITRIX_ERROR` | The body carried `fileId: null` (message "The field FILE_ID is required."). Remove `fileId` from the body |
| 403 | `SCOPE_DENIED` | The key lacks the `documentgenerator` scope |
| 401 | `TOKEN_MISSING` | The key has no configured tokens |

Full list of common API errors — [Errors](/docs/errors).

## Known specifics

**A call with `fileId` succeeds but does not change the file.** A call with a numeric `fileId` and no `file` returns `200` and `success: true`, but the template file stays the same. If you pass both fields, `file` is applied. So `success: true` does not confirm the replacement: check the file with [`GET /v1/doc-templates/:id/download`](/docs/entities/doc-templates/download).

**The `file` content is not validated.** The call returns `200` even when `file` does not carry a `.docx`: the template stores the content as sent, and the file downloaded afterwards does not open as a document. Pass only `.docx` file content in `file`.

## See also

- [Get template](/docs/entities/doc-templates/get)
- [Download REST template](/docs/entities/doc-templates/download)
- [Create template](/docs/entities/doc-templates/create)
- [Template fields](/docs/entities/doc-templates/fields)
