لوكلاء AI: ملف markdown لهذه الصفحة — /docs-content-en/entities/documents.md فهرس التوثيق — /llms.txt

مقالات التوثيق متاحة حاليًا باللغة الإنجليزية فقط.

Documents

A document is a ready-to-use file that Bitrix24 generates from a template by substituting values. Each document is created from a document template and a data provider.

Bitrix24 API: documentgenerator.document.* Scope: documentgenerator

For CRM documents, select a template in the CRM template section; app templates live in /v1/doc-templates. The /v1/crm-documents routes use crm.documentgenerator.document.* and the crm scope.

The PDF and the image are generated asynchronously. If a download returns 409 DOCUMENT_NOT_READY, retry later. Public sharing is a separate action: an enabled public URL works without authentication.

Download document DOCX

GET /v1/documents/:id/download

Downloads the DOCX file of a generated document through Vibecode: the platform adds Bitrix24 authorization to the request automatically. A CRM record document is downloaded the same way through its own route.

Document Route Scope
DocumentApp document RouteGET /v1/documents/:id/download Scopedocumentgenerator
DocumentCRM record document RouteGET /v1/crm-documents/:id/download Scopecrm

Parameters

Parameter Type Required Description
Parameterid (path) Typenumber Requiredyes DescriptionDocument ID, a positive integer. App documents: GET /v1/documents, CRM record documents: GET /v1/crm-documents

No request body is sent. The examples below are for an app document. For a CRM record document, replace documents with crm-documents in the URL.

Examples

curl — personal key

Terminal
curl --fail-with-body "https://vibecode.bitrix24.com/v1/documents/2001/download" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -o document-2001.docx

curl — OAuth application

Terminal
curl --fail-with-body "https://vibecode.bitrix24.com/v1/documents/2001/download" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -o document-2001.docx

JavaScript — personal key

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/documents/2001/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/documents/2001/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 HTTP status is 200 OK and the response body contains the bytes of the DOCX file. File details come in the headers.

Header Example value Description
HeaderContent-Type Example valueapplication/vnd.openxmlformats-officedocument.wordprocessingml.document DescriptionContent type that Bitrix24 returned for the document file
HeaderContent-Disposition Example valueattachment; filename="document-2001.docx" DescriptionFile name for saving, in the form document-<id>.docx. The document title is not included

Response example

http
HTTP/1.1 200 OK
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Disposition: attachment; filename="document-2001.docx"
Content-Length: 914

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

Error response example

404 — document not found:

JSON
{
  "success": false,
  "error": {
    "code": "ENTITY_NOT_FOUND",
    "message": "Document not found."
  }
}

Errors

HTTP Code Description
HTTP400 CodeINVALID_PARAMS Descriptionid is not a positive integer. Message: Document ID must be a positive integer.
HTTP404 CodeENTITY_NOT_FOUND DescriptionNo document with this id. Message: Document not found.
HTTP409 CodeDOCUMENT_NOT_READY DescriptionCRM record documents only: the document has no DOCX file yet. Retry the request in a few seconds
HTTP502 CodeDOWNLOAD_FAILED DescriptionBitrix24 did not return the file: it responded with an error code, sent JSON instead of the file, pointed to a URL outside the Bitrix24 account, or the response could not be read in full. For an app document, also when the file is larger than 10 MiB
HTTP422 CodeBITRIX_ERROR DescriptionBitrix24 rejected the request. The reason is in error.message
HTTP403 CodeBITRIX_ACCESS_DENIED DescriptionBitrix24 denied access to the document. For a CRM record document, also when the record it is attached to does not exist
HTTP403 CodeSCOPE_DENIED DescriptionThe key lacks the route scope: documentgenerator for an app document, crm for a CRM record document
HTTP401 CodeMISSING_API_KEY DescriptionThe X-Api-Key header is missing
HTTP401 CodeTOKEN_MISSING DescriptionNo tokens are mapped to the key — an OAuth application key was called without a user session

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 just like a full-access key.

DOCX is ready before PDF and image. In the first seconds after a document is created, the PDF and image routes respond with 409 DOCUMENT_NOT_READY, while this route already returns the file.

The downloadUrlMachine field points to this route. In the responses of GET /v1/documents/:id and GET /v1/crm-documents/:id, the field contains the route URL for the same document. API responses contain no Bitrix24 access secrets.

See also