[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-entities\u002Fdoc-templates\u002Fdownload":3,"docs-tabs-entities\u002Fdoc-templates\u002Fdownload":6},{"content":4,"lastmod":5},"## Download a REST document template\n\n`GET \u002Fv1\u002Fdoc-templates\u002F:id\u002Fdownload`\n\nDownloads the source .docx file of an app template with `moduleId: rest` through Vibecode: the platform adds the Bitrix24 authorization to the request itself.\n\n## Parameters\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|---------|\n| `id` (path) | number | yes | Template ID. List: [`GET \u002Fv1\u002Fdoc-templates`](\u002Fdocs\u002Fentities\u002Fdoc-templates\u002Flist) |\n\nNo request body is sent.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -H \"X-Api-Key: YOUR_API_KEY\" \\\n  \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fdoc-templates\u002F237\u002Fdownload\" \\\n  -o template-237.docx\n```\n\n### curl — OAuth application\n\n```bash\ncurl -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fdoc-templates\u002F237\u002Fdownload\" \\\n  -o template-237.docx\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch(\n  'https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fdoc-templates\u002F237\u002Fdownload',\n  { headers: { 'X-Api-Key': 'YOUR_API_KEY' } }\n)\n\nif (!res.ok) {\n  const body = await res.json()\n  throw new Error(body.error?.code ?? String(res.status))\n}\n\nconst blob = await res.blob()\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch(\n  'https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fdoc-templates\u002F237\u002Fdownload',\n  {\n    headers: {\n      'X-Api-Key': 'YOUR_APP_KEY',\n      'Authorization': 'Bearer USER_SESSION_TOKEN',\n    },\n  }\n)\n\nif (!res.ok) {\n  const body = await res.json()\n  throw new Error(body.error?.code ?? String(res.status))\n}\n\nconst blob = await res.blob()\n```\n\n## Response fields\n\nOn success, the response has HTTP status `200 OK`, and the body contains the bytes of the .docx file with no JSON envelope. File details come in headers.\n\n| Header | Example value | Description |\n|-----------|-----------------|----------|\n| `Content-Type` | `application\u002Fvnd.openxmlformats-officedocument.wordprocessingml.document` | Content type that Bitrix24 returned for the template file |\n| `Content-Disposition` | `attachment; filename=\"template-237.docx\"` | File name for saving. Built from the template `id` as `template-\u003Cid>.docx`; the template name is not part of it |\n\n## Response example\n\n```http\nHTTP\u002F1.1 200 OK\nContent-Type: application\u002Fvnd.openxmlformats-officedocument.wordprocessingml.document\nContent-Disposition: attachment; filename=\"template-237.docx\"\nTransfer-Encoding: chunked\n\n\u003Cbinary .docx content, 922 bytes, starts with PK>\n```\n\n## Error response example\n\n400 — invalid `id`:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"INVALID_PARAMS\",\n    \"message\": \"Template ID must be a positive integer.\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|----------|\n| 400 | `INVALID_PARAMS` | `id` is not a positive integer. Message: `Template ID must be a positive integer.` |\n| 404 | `ENTITY_NOT_FOUND` | No template with this `id` exists |\n| 404 | `ENTITY_NOT_FOUND` | The template exists, but it is not a `rest` module template or has no download URL. Message: `REST template download not found.` |\n| 403 | `BITRIX_ACCESS_DENIED` | The template belongs to another module, for example CRM. CRM templates are downloaded through [`GET \u002Fv1\u002Fcrm-document-templates\u002F:id\u002Fdownload`](\u002Fdocs\u002Fentities\u002Fcrm-document-templates\u002Fdownload) |\n| 502 | `DOWNLOAD_FAILED` | Bitrix24 did not return the file: it responded with an error code, for example `Bitrix24 returned 403`, or returned a URL outside the portal or without HTTPS. An on-premise Bitrix24 portal reachable only over HTTP always gets this error — set up HTTPS on it to transfer files |\n| 422 | `BITRIX_ERROR` | Bitrix24 rejected the request to read the template. The reason is in `error.message` |\n| 403 | `SCOPE_DENIED` | The key lacks the `documentgenerator` scope |\n| 401 | `TOKEN_MISSING` | The key has no configured tokens |\n| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is not passed |\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**A read-only key works.** Downloading does not count as a write, so a key without write permission gets the file the same way as a full-access key.\n\n**The `downloadMachine` field points here.** In the responses of [`GET \u002Fv1\u002Fdoc-templates\u002F:id`](\u002Fdocs\u002Fentities\u002Fdoc-templates\u002Fget), [`GET \u002Fv1\u002Fdoc-templates`](\u002Fdocs\u002Fentities\u002Fdoc-templates\u002Flist) and [`POST \u002Fv1\u002Fdoc-templates`](\u002Fdocs\u002Fentities\u002Fdoc-templates\u002Fcreate), this field contains the URL of this endpoint for a template with `moduleId: rest`. When following it, pass the same `X-Api-Key` with the `documentgenerator` scope — the file does not open without a key. For templates of other modules, the field does not contain this endpoint's URL.\n\n## See also\n\n- [Get a template](\u002Fdocs\u002Fentities\u002Fdoc-templates\u002Fget)\n- [List templates](\u002Fdocs\u002Fentities\u002Fdoc-templates\u002Flist)\n- [Create a template](\u002Fdocs\u002Fentities\u002Fdoc-templates\u002Fcreate)\n- [Document templates](\u002Fdocs\u002Fentities\u002Fdoc-templates)\n- [Download a CRM document template](\u002Fdocs\u002Fentities\u002Fcrm-document-templates\u002Fdownload)\n","2026-10-22",{},1794739372522]