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

Documents

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

Bitrix24 API: documentgenerator.document.* Scope: documentgenerator

Create document

POST /v1/documents

Creates a document from a template: Bitrix24 builds the file, substituting values from the data provider into the template.

Request fields (body)

Minimum to create: templateId, providerClassName, value.

Field Type Req. Description
templateId number Identifier of the template the document is built from. Template list: GET /v1/doc-templates
providerClassName string Data provider class — the source of values for template labels. For example Bitrix\DocumentGenerator\DataProvider\Rest
value string External identifier of the source object the provider pulls values from. For example ORDER-1024
values object Values for the template's label fields. The key is the label name, the value is the substituted text. For example {"DocumentNumber":"2026-001"}
fields object Document field formatting description
stampsEnabled boolean Insert stamps and signatures into the document

Examples

curl — personal key

Terminal
curl -X POST https://vibecode.bitrix24.com/v1/documents \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": 53,
    "providerClassName": "Bitrix\\DocumentGenerator\\DataProvider\\Rest",
    "value": "ORDER-1024",
    "values": { "DocumentNumber": "2026-001" }
  }'

curl — OAuth application

Terminal
curl -X POST https://vibecode.bitrix24.com/v1/documents \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "templateId": 53,
    "providerClassName": "Bitrix\\DocumentGenerator\\DataProvider\\Rest",
    "value": "ORDER-1024",
    "values": { "DocumentNumber": "2026-001" }
  }'

JavaScript — personal key

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/documents', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    templateId: 53,
    providerClassName: 'Bitrix\\DocumentGenerator\\DataProvider\\Rest',
    value: 'ORDER-1024',
    values: { DocumentNumber: '2026-001' },
  }),
})

const { success, data } = await res.json()
console.log('Document ID:', data.id)

JavaScript — OAuth application

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/documents', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    templateId: 53,
    providerClassName: 'Bitrix\\DocumentGenerator\\DataProvider\\Rest',
    value: 'ORDER-1024',
    values: { DocumentNumber: '2026-001' },
  }),
})

const { success, data } = await res.json()

Response fields

Field Type Description
success boolean Always true on success
data object The created document with all fields — see Document fields

The provider field in the response matches the providerClassName passed in the request.

Response example

JSON
{
  "success": true,
  "data": {
    "id": 51,
    "title": "Supply contract 2026-001",
    "number": "2026-001",
    "templateId": 53,
    "provider": "Bitrix\\DocumentGenerator\\DataProvider\\Rest",
    "value": "ORDER-1024",
    "fileId": 241,
    "pdfId": 245,
    "imageId": 243,
    "createTime": "2026-03-18T17:27:48+00:00",
    "updateTime": "2026-03-18T17:27:48+00:00",
    "createdBy": 503,
    "updatedBy": null,
    "values": { "DocumentNumber": "2026-001" },
    "stampsEnabled": false,
    "publicUrl": null,
    "downloadUrl": "https://example.bitrix24.com/bitrix/services/main/ajax.php?action=documentgenerator.api.document.getfile&id=51",
    "pdfUrl": "https://example.bitrix24.com/bitrix/services/main/ajax.php?action=documentgenerator.api.document.getpdf&id=51"
  }
}

Error response example

403 — no scope:

JSON
{
  "success": false,
  "error": {
    "code": "SCOPE_DENIED",
    "message": "This endpoint requires 'documentgenerator' scope"
  }
}

Errors

HTTP Code Description
403 SCOPE_DENIED The API key does not have the documentgenerator scope
401 MISSING_API_KEY The X-Api-Key header was not provided
400 MISSING_REQUIRED_FIELDS One of the required fields is missing: templateId, providerClassName, or value
404 ENTITY_NOT_FOUND The template with the given templateId was not found or is unavailable
422 BITRIX_ERROR The data provider did not return an object for the given value

Full list of common API errors — Errors.

See also