# CRM document templates

A CRM document template is a .docx file with placeholder tags that Bitrix24 uses to generate documents for deals, contacts, companies and other CRM records.

Bitrix24 API: `crm.documentgenerator.template.*`
Scope: `crm`

## Operations

- [Create a CRM document template](./crm-document-templates/create.md) — `POST /v1/crm-document-templates`
- [List CRM document templates](./crm-document-templates/list.md) — `GET /v1/crm-document-templates`
- [Get a CRM document template](./crm-document-templates/get.md) — `GET /v1/crm-document-templates/:id`
- [Update a CRM document template](./crm-document-templates/update.md) — `PATCH /v1/crm-document-templates/:id`
- [Delete a CRM document template](./crm-document-templates/delete.md) — `DELETE /v1/crm-document-templates/:id`
- [Templates for a CRM record](./crm-document-templates/available.md) — `GET /v1/crm-document-templates/available`
- [Download a template](./crm-document-templates/download.md) — `GET /v1/crm-document-templates/:id/download`

## Key fields

| Field | Description |
|------|---------|
| `id` | Template ID. List: [`GET /v1/crm-document-templates`](./crm-document-templates/list.md) |
| `name` | Template name |
| `entityTypeId` | CRM record types the template is available for: `2` — deal, `3` — contact, `4` — company. Smart process types: [`GET /v1/smart-processes`](/docs/entities/smart-processes) |
| `numeratorId` | ID of the numerator that assigns numbers to documents. No `/v1/...` route lists numerators |
| `region` | Template region, for example `uk` |
| `users` | Access codes that define which employees see the template, for example `UA` — all employees, `U<id>` — the employee with this ID from [`GET /v1/users`](/docs/entities/users) |
| `moduleId` | Owner module, always `crm` for templates in this section |

## What to know before you start

1. This section works only with CRM templates, whose `moduleId` is `crm`. Application templates with `moduleId: rest` are in the [Document templates](/docs/entities/doc-templates) section and require the `documentgenerator` scope.
2. When you create or update a template, pass the template file only as a base64 string in the `file` field. Uploading from Drive by `fileId` is not supported.
3. A template does not generate a document by itself. [Create a CRM document](/docs/entities/documents/crm-create) from the selected template, then find it in the [CRM document list](/docs/entities/documents/crm-list).
4. [`GET /v1/crm-document-templates/available`](./crm-document-templates/available.md) shows which templates apply to a specific deal or contact: its response includes only templates bound to the type of that record and, for a deal, to its pipeline.
5. A deal's `entityTypeId` is stored expanded by pipeline. The create and update responses with `entityTypeId` in the body echo the value you sent, while the get response and an update without this field show the stored value: a template created with `entityTypeId: [2]` reads back as `2_category_0`, `2_category_1` and so on — one value per pipeline of the Bitrix24 account. `2_category_0` is the general pipeline. The other numbers are pipeline IDs from [`GET /v1/deal-categories`](/docs/entities/deal-categories). A smart process with pipelines is stored the same way, but in the form `174_3`: the smart process type and the ID of its pipeline from [`GET /v1/categories/:entityTypeId`](/docs/entities/categories/list).

## Typical scenario

1. Create a template from your own `.docx` via [`POST /v1/crm-document-templates`](./crm-document-templates/create.md) or pick an existing one in [`GET /v1/crm-document-templates`](./crm-document-templates/list.md).
2. Check that the template is available for the target record: [`GET /v1/crm-document-templates/available?entityTypeId=2&entityId=575`](./crm-document-templates/available.md).
3. Generate a document from the template via [`POST /v1/crm-documents`](/docs/entities/documents/crm-create).

## Limits

| Limit | Value |
|-------|----------|
| JSON body on create and update | up to 3 MiB |
| Template file | up to 2 MiB after decoding `file` |
| Rate limit | shared across the Vibecode API — see [Limits and optimization](/docs/optimization) |

## See also

- [Documents](/docs/entities/documents)
- [Document templates](/docs/entities/doc-templates)
- [Entity reference](/docs/entity-api)
