[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-entities\u002Fcrm-document-templates\u002Fcreate":3,"docs-tabs-entities\u002Fcrm-document-templates\u002Fcreate":6},{"content":4,"lastmod":5},"## Create a CRM document template\n\n`POST \u002Fv1\u002Fcrm-document-templates`\n\nCreates a CRM document template from a .docx file passed as a base64 string and binds it to CRM record types. Fields go in the JSON root without a wrapper.\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|---------|\n| `name` | string | yes | Template name |\n| `file` | string | yes | Contents of your `.docx` file as a base64 string, no more than 2 MiB after decoding. See \"Known specifics\" for how to get the string |\n| `numeratorId` | number | yes | ID of the numerator that assigns numbers to documents. A positive integer. The list of numerators is not exposed through `\u002Fv1\u002F...` |\n| `region` | string | yes | Template region, for example `uk` |\n| `entityTypeId` | array | yes | Non-empty array of CRM record types, numbers or strings: `2` — deal, `3` — contact, `4` — company. Smart process types — [`GET \u002Fv1\u002Fsmart-processes`](\u002Fdocs\u002Fentities\u002Fsmart-processes) |\n| `users` | array | no | Array of access codes as strings: `UA` — all employees, `U\u003Cid>` — the employee with this ID from [`GET \u002Fv1\u002Fusers`](\u002Fdocs\u002Fentities\u002Fusers). When called with a personal key without this field, the template is available only to the key owner: the response returns that employee's `U\u003Cid>` |\n| `active` | string | no | Whether the template is active: `Y` or `N`. Defaults to `Y` |\n| `withStamps` | string | no | Stamps and signatures in documents: `Y` or `N`. Defaults to `N` |\n| `sort` | number | no | Sort index. Defaults to `500` |\n| `code` | string | no | Template symbolic code |\n\nThe fields `id`, `fileId`, `moduleId`, `download`, `downloadMachine`, `isDeleted`, `isDefault`, `createTime`, `updateTime`, `createdBy`, `updatedBy`, `providers` are read-only. A request with any of them is rejected with `400 READONLY_FIELD`. The name is compared ignoring case and underscores: `module_id` and `ModuleId` are rejected too.\n\n## Examples\n\nIn the examples, `contract.docx` is your template file. The request body is assembled into the `template.json` file and then sent.\n\n### curl — personal key\n\n```bash\nprintf '{\"name\":\"Supply agreement\",\"numeratorId\":1,\"region\":\"uk\",\"entityTypeId\":[2],\"users\":[\"UA\"],\"file\":\"%s\"}' \\\n  \"$(base64 \u003C contract.docx | tr -d '\\n')\" > template.json\n\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcrm-document-templates\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  --data-binary @template.json\n```\n\n### curl — OAuth application\n\n```bash\nprintf '{\"name\":\"Supply agreement\",\"numeratorId\":1,\"region\":\"uk\",\"entityTypeId\":[2],\"users\":[\"UA\"],\"file\":\"%s\"}' \\\n  \"$(base64 \u003C contract.docx | tr -d '\\n')\" > template.json\n\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcrm-document-templates\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  --data-binary @template.json\n```\n\n### JavaScript — personal key\n\n```javascript\nimport { readFile } from 'node:fs\u002Fpromises'\n\nconst file = (await readFile('contract.docx')).toString('base64')\n\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcrm-document-templates', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    name: 'Supply agreement',\n    numeratorId: 1,\n    region: 'uk',\n    entityTypeId: [2],\n    users: ['UA'],\n    file,\n  }),\n})\n\nconst { success, data } = await res.json()\nconsole.log('Template ID:', data.id)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nimport { readFile } from 'node:fs\u002Fpromises'\n\nconst file = (await readFile('contract.docx')).toString('base64')\n\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcrm-document-templates', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    name: 'Supply agreement',\n    numeratorId: 1,\n    region: 'uk',\n    entityTypeId: [2],\n    users: ['UA'],\n    file,\n  }),\n})\n\nconst { success, data } = await res.json()\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data` | object | The created template |\n| `data.id` | string | Template ID, as a string |\n| `data.name` | string | Template name |\n| `data.region` | string | Template region |\n| `data.code` | string \\| null | Template symbolic code, `null` — no code set |\n| `data.download` | string | Template file download URL in the Bitrix24 web interface. To download through the API, use `downloadMachine` |\n| `data.active` | string | Whether the template is active: `Y` or `N` |\n| `data.moduleId` | string | Owner module, always `crm` |\n| `data.numeratorId` | string | Numerator ID, as a string |\n| `data.withStamps` | string | Stamps and signatures: `Y` or `N` |\n| `data.users` | object | Access codes as an object, each code serves as both key and value: `{\"UA\": \"UA\"}` |\n| `data.isDeleted` | string | Deletion flag: `N` for an active template |\n| `data.sort` | string | Sort index, as a string |\n| `data.createTime` | string | Creation date in ISO 8601 with a time zone offset |\n| `data.updateTime` | string | Last modification date in ISO 8601 with a time zone offset |\n| `data.entityTypeId` | array | CRM record types as strings, exactly as passed in the request. When the template is read, the deal type expands by funnel — see [What to know before you start](\u002Fdocs\u002Fentities\u002Fcrm-document-templates#what-to-know-before-you-start) |\n| `data.downloadMachine` | string | `.docx` download URL through the Vibecode API — [`GET \u002Fv1\u002Fcrm-document-templates\u002F:id\u002Fdownload`](\u002Fdocs\u002Fentities\u002Fcrm-document-templates\u002Fdownload) |\n\n## Response example\n\nHTTP `201`:\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"id\": \"263\",\n    \"name\": \"Supply agreement\",\n    \"region\": \"uk\",\n    \"code\": null,\n    \"download\": \"https:\u002F\u002Fexample.bitrix24.com\u002Fbitrix\u002Fservices\u002Fmain\u002Fajax.php?action=crm.documentgenerator.template.download&SITE_ID=s1&id=263\",\n    \"active\": \"Y\",\n    \"moduleId\": \"crm\",\n    \"numeratorId\": \"1\",\n    \"withStamps\": \"N\",\n    \"users\": {\n      \"UA\": \"UA\"\n    },\n    \"isDeleted\": \"N\",\n    \"sort\": \"500\",\n    \"createTime\": \"2026-10-08T13:20:29+00:00\",\n    \"updateTime\": \"2026-10-08T13:20:29+00:00\",\n    \"entityTypeId\": [\"2\"],\n    \"downloadMachine\": \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcrm-document-templates\u002F263\u002Fdownload\"\n  }\n}\n```\n\n## Error response example\n\n400 — a required field is missing:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"MISSING_REQUIRED_FIELDS\",\n    \"message\": \"Required field 'numeratorId' is missing.\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `MISSING_REQUIRED_FIELDS` | One of the required fields is missing, or its value is `null`, an empty string or an empty array. An empty body `{}` gets the same code |\n| 400 | `INVALID_PARAMS` | `file` is not a base64 string. A placeholder instead of the file contents is rejected with this code before the request reaches Bitrix24 |\n| 400 | `INVALID_PARAMS` | `users` is not an array of non-empty strings, for example, the `{\"UA\": \"UA\"}` object was passed in the shape the response returns |\n| 400 | `INVALID_PARAMS` | `entityTypeId` is not an array, or it contains a value that is neither a positive number nor a non-empty string |\n| 400 | `INVALID_PARAMS` | `name` or `region` is not a string, `numeratorId` is not a positive integer |\n| 400 | `INVALID_PARAMS` | The request body is not a JSON object |\n| 400 | `READONLY_FIELD` | The body contains a read-only field, for example `moduleId` or `fileId` |\n| 413 | `PAYLOAD_TOO_LARGE` | The file exceeds 2 MiB after decoding `file`, or the JSON body exceeds 3 MiB |\n| 429 | `LARGE_BODY_BACKEND_BUSY` | The body exceeds 1 MiB and the platform is already processing the maximum volume of large bodies. Retry after `Retry-After` seconds |\n| 422 | `BITRIX_WRITE_NOT_APPLIED` | The template was created, but Bitrix24 did not save all of the passed `entityTypeId` or `users`. The created template ID is in `error.details.createdTemplateId`. Check the template with [`GET \u002Fv1\u002Fcrm-document-templates\u002F:id`](\u002Fdocs\u002Fentities\u002Fcrm-document-templates\u002Fget) before retrying: a repeated request creates another template |\n| 422 | `BITRIX_ERROR` | Bitrix24 rejected the creation. The reason text is in `error.message` |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key works in read-only mode |\n| 403 | `SCOPE_DENIED` | The key lacks the `crm` scope |\n| 401 | `TOKEN_MISSING` | The key has no configured tokens |\n| 429 | `RATE_LIMITED` | Bitrix24 rate-limited requests to the portal. Retry after the delay in the `Retry-After` header |\n\nFull list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**How to get the `file` value.** Build the base64 string from your file with `base64 \u003C contract.docx | tr -d '\\n'`, on macOS — `base64 -i contract.docx | tr -d '\\n'`. Removing line breaks from the output is mandatory: a string with line breaks fails the base64 check.\n\n## See also\n\n- [List CRM document templates](\u002Fdocs\u002Fentities\u002Fcrm-document-templates\u002Flist)\n- [Get a CRM document template](\u002Fdocs\u002Fentities\u002Fcrm-document-templates\u002Fget)\n- [Update a CRM document template](\u002Fdocs\u002Fentities\u002Fcrm-document-templates\u002Fupdate)\n- [Delete a CRM document template](\u002Fdocs\u002Fentities\u002Fcrm-document-templates\u002Fdelete)\n- [Download a template](\u002Fdocs\u002Fentities\u002Fcrm-document-templates\u002Fdownload)\n- [Create a CRM document](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fcrm-create)\n- [Document templates](\u002Fdocs\u002Fentities\u002Fdoc-templates)\n","2026-10-09",{},1795415216395]