For AI agents: markdown of this page — /docs-content-en/entities/doc-templates/download.md documentation index — /llms.txt

Download a REST document template

GET /v1/doc-templates/:id/download

Downloads the source .docx file of an app template with moduleId: rest through Vibecode: the platform adds the Bitrix24 authorization to the request itself.

Parameters

Parameter Type Required Description
Parameterid (path) Typenumber Requiredyes DescriptionTemplate ID. List: GET /v1/doc-templates

No request body is sent.

Examples

curl — personal key

Terminal
curl -H "X-Api-Key: YOUR_API_KEY" \
  "https://vibecode.bitrix24.com/v1/doc-templates/237/download" \
  -o template-237.docx

curl — OAuth application

Terminal
curl -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  "https://vibecode.bitrix24.com/v1/doc-templates/237/download" \
  -o template-237.docx

JavaScript — personal key

javascript
const res = await fetch(
  'https://vibecode.bitrix24.com/v1/doc-templates/237/download',
  { headers: { 'X-Api-Key': 'YOUR_API_KEY' } }
)

if (!res.ok) {
  const body = await res.json()
  throw new Error(body.error?.code ?? String(res.status))
}

const blob = await res.blob()

JavaScript — OAuth application

javascript
const res = await fetch(
  'https://vibecode.bitrix24.com/v1/doc-templates/237/download',
  {
    headers: {
      'X-Api-Key': 'YOUR_APP_KEY',
      'Authorization': 'Bearer USER_SESSION_TOKEN',
    },
  }
)

if (!res.ok) {
  const body = await res.json()
  throw new Error(body.error?.code ?? String(res.status))
}

const blob = await res.blob()

Response fields

On 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.

Header Example value Description
HeaderContent-Type Example valueapplication/vnd.openxmlformats-officedocument.wordprocessingml.document DescriptionContent type that Bitrix24 returned for the template file
HeaderContent-Disposition Example valueattachment; filename="template-237.docx" DescriptionFile name for saving. Built from the template id as template-<id>.docx; the template name is not part of it

Response example

http
HTTP/1.1 200 OK
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Disposition: attachment; filename="template-237.docx"
Transfer-Encoding: chunked

<binary .docx content, 922 bytes, starts with PK>

Error response example

400 — invalid id:

JSON
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "Template ID must be a positive integer."
  }
}

Errors

HTTP Code Description
HTTP400 CodeINVALID_PARAMS Descriptionid is not a positive integer. Message: Template ID must be a positive integer.
HTTP404 CodeENTITY_NOT_FOUND DescriptionNo template with this id exists
HTTP404 CodeENTITY_NOT_FOUND DescriptionThe template exists, but it is not a rest module template or has no download URL. Message: REST template download not found.
HTTP403 CodeBITRIX_ACCESS_DENIED DescriptionThe template belongs to another module, for example CRM. CRM templates are downloaded through GET /v1/crm-document-templates/:id/download
HTTP502 CodeDOWNLOAD_FAILED DescriptionBitrix24 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
HTTP422 CodeBITRIX_ERROR DescriptionBitrix24 rejected the request to read the template. The reason is in error.message
HTTP403 CodeSCOPE_DENIED DescriptionThe key lacks the documentgenerator scope
HTTP401 CodeTOKEN_MISSING DescriptionThe key has no configured tokens
HTTP401 CodeMISSING_API_KEY DescriptionThe X-Api-Key header is not passed
HTTP429 CodeRATE_LIMITED DescriptionBitrix24 rate-limited requests to the portal. Retry after the delay in the Retry-After header

Full list of common API errors — Errors.

Known specifics

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.

The downloadMachine field points here. In the responses of GET /v1/doc-templates/:id, GET /v1/doc-templates and POST /v1/doc-templates, 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.

See also