[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-entities\u002Fdocuments\u002Fcrm-create":3,"docs-tabs-entities\u002Fdocuments\u002Fcrm-create":6},{"content":4,"lastmod":5},"## Create a CRM document\n\n`POST \u002Fv1\u002Fcrm-documents`\n\nGenerates a document from a CRM template for a CRM record (a deal, contact, company or smart process item) and attaches it to that record. Fields are passed at the JSON root without a fields wrapper.\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|---------|\n| `templateId` | number | yes | CRM template ID, a positive integer. Templates available for a record: [`GET \u002Fv1\u002Fcrm-document-templates\u002Favailable`](\u002Fdocs\u002Fentities\u002Fcrm-document-templates\u002Favailable) |\n| `entityTypeId` | number | yes | CRM record type, a positive integer: `2` — deal, `3` — contact, `4` — company. Other types are in the \"CRM record types\" list on the [`GET \u002Fv1\u002Fcrm-documents`](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fcrm-list) page |\n| `entityId` | number | yes | Record ID, a positive integer. The source depends on the type: deals — [`GET \u002Fv1\u002Fdeals`](\u002Fdocs\u002Fentities\u002Fdeals\u002Flist), contacts — [`GET \u002Fv1\u002Fcontacts`](\u002Fdocs\u002Fentities\u002Fcontacts\u002Flist), companies — [`GET \u002Fv1\u002Fcompanies`](\u002Fdocs\u002Fentities\u002Fcompanies\u002Flist) |\n| `values` | object | no | Template field values. For example, `DocumentNumber` sets the document number |\n| `stampsEnabled` | boolean | no | Enable stamps and signatures. If the field is not passed, stamps are disabled. The `changeStampsEnabled` response field shows whether the template has stamps |\n\nThe request accepts no other fields, such as `title`. The stamps flag is passed only at the body root, not inside `values`.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcrm-documents\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"templateId\": 87,\n    \"entityTypeId\": 2,\n    \"entityId\": 8781,\n    \"values\": { \"DocumentNumber\": \"VD-100\" }\n  }'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcrm-documents\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\n    \"templateId\": 87,\n    \"entityTypeId\": 2,\n    \"entityId\": 8781,\n    \"values\": { \"DocumentNumber\": \"VD-100\" }\n  }'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcrm-documents', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\n    templateId: 87,\n    entityTypeId: 2,\n    entityId: 8781,\n    values: { DocumentNumber: 'VD-100' },\n  }),\n})\n\nconst { success, data } = await res.json()\nconsole.log('Document:', data.id, data.number)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcrm-documents', {\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    templateId: 87,\n    entityTypeId: 2,\n    entityId: 8781,\n    values: { DocumentNumber: 'VD-100' },\n  }),\n})\n\nconst { success, data } = await res.json()\n```\n\n## Response fields\n\nReturns HTTP status `201 Created` and the created document. The full description of the document fields is on the [Get a CRM document](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fcrm-get) page.\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data.id` | number | ID of the created document. Returned as a number, unlike the [`GET \u002Fv1\u002Fcrm-documents\u002F:id`](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fcrm-get) response |\n| `data.title` | string | Document title generated from the template |\n| `data.number` | string | Document number. Set by `values.DocumentNumber` or by the template numerator |\n| `data.templateId` | string | Template ID |\n| `data.entityTypeId` | string | CRM record type |\n| `data.entityId` | number | CRM record ID |\n| `data.values` | object | Template field values as passed, along with service keys |\n| `data.stampsEnabled` | boolean | Whether stamps and signatures are enabled |\n| `data.changeStampsEnabled` | boolean | Whether stamps can be enabled: `false` if the template has none |\n| `data.createdBy` | number | Creator ID. List: [`GET \u002Fv1\u002Fusers`](\u002Fdocs\u002Fentities\u002Fusers) |\n| `data.downloadUrl` | string | Link for an employee to open the DOCX file in a browser |\n| `data.downloadUrlMachine` | string | URL of [`\u002Fv1\u002Fcrm-documents\u002F:id\u002Fdownload`](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fdownload). Requires `X-Api-Key` with the `crm` scope |\n\n## Response example\n\nThe main fields are shown. Full list: [Get a CRM document](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fcrm-get).\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"changeStampsEnabled\": false,\n    \"downloadUrl\": \"https:\u002F\u002Fexample.bitrix24.com\u002Fbitrix\u002Fservices\u002Fmain\u002Fajax.php?action=crm.documentgenerator.document.download&SITE_ID=s1&id=1981\",\n    \"publicUrl\": null,\n    \"title\": \"Addresses VD-100\",\n    \"number\": \"VD-100\",\n    \"id\": 1981,\n    \"createTime\": \"2026-10-08T17:55:00+00:00\",\n    \"createdBy\": 1317,\n    \"stampsEnabled\": false,\n    \"isTransformationError\": false,\n    \"values\": {\n      \"productsTableVariant\": \"\",\n      \"stampsEnabled\": false,\n      \"_creationMethod\": \"rest\",\n      \"DocumentNumber\": \"VD-100\"\n    },\n    \"templateId\": \"87\",\n    \"entityId\": 8781,\n    \"entityTypeId\": \"2\",\n    \"downloadUrlMachine\": \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fcrm-documents\u002F1981\u002Fdownload\"\n  }\n}\n```\n\n## Error response example\n\n404 — no template with this `templateId` exists:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"ENTITY_NOT_FOUND\",\n    \"message\": \"Template not found\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `MISSING_REQUIRED_FIELDS` | The body is not a JSON object, for example an array. Message: `A document body is required` |\n| 400 | `MISSING_REQUIRED_FIELDS` | `templateId`, `entityTypeId` or `entityId` is missing, or the value is not a positive integer. Message: `templateId, entityTypeId and entityId must be positive integers` |\n| 400 | `READONLY_FIELD` | The body contains a field not listed in the table above, for example `title` |\n| 400 | `INVALID_PARAMS` | `values` is not an object, `values` contains `stampsEnabled`, or `stampsEnabled` is not a boolean |\n| 404 | `ENTITY_NOT_FOUND` | No template with this `templateId` exists. Message: `Template not found` |\n| 422 | `BITRIX_ERROR` | This `entityTypeId` is not supported for documents, for example `999`. Message: `No provider for entityTypeId` |\n| 502 | `BITRIX_INVALID_RESPONSE` | Bitrix24 responded without a document |\n| 403 | `BITRIX_ACCESS_DENIED` | No access to the CRM record, including a contact that does not exist. Message: `Access denied` |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode |\n| 403 | `SCOPE_DENIED` | The key lacks the `crm` scope |\n| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |\n| 401 | `TOKEN_MISSING` | No tokens are mapped to the key: an OAuth application key was called without a user session |\n\nFull list of common API errors: [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**Deal existence is not checked.** With `entityTypeId: 2`, a document is created even for an `entityId` that matches no deal: the response is `201`. For a contact with a nonexistent ID, `403 BITRIX_ACCESS_DENIED` is returned. Check the record beforehand, for example via [`GET \u002Fv1\u002Fdeals\u002F:id`](\u002Fdocs\u002Fentities\u002Fdeals\u002Fget).\n\n**PDF and image appear later.** The creation response contains only DOCX links. Links to the PDF and image appear in the [`GET \u002Fv1\u002Fcrm-documents\u002F:id`](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fcrm-get) response once the files are ready. Until then, downloading the [PDF](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fpdf) returns `409 DOCUMENT_NOT_READY`.\n\n**IDs can be passed as strings.** `\"templateId\": \"87\"` is accepted the same way as `87`.\n\n## See also\n\n- [Get a CRM document](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fcrm-get)\n- [Update a CRM document](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fcrm-update)\n- [Upload a CRM document](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fcrm-upload)\n- [Documents by CRM entity](\u002Fdocs\u002Fentities\u002Fdocuments\u002Fcrm-list)\n- [Templates for a CRM record](\u002Fdocs\u002Fentities\u002Fcrm-document-templates\u002Favailable)\n- [Documents](\u002Fdocs\u002Fentities\u002Fdocuments)\n","2026-10-08",{},1794739373646]