## Update a CRM document

`PATCH /v1/crm-documents/:id`

Changes template field values or the stamps flag of a CRM record document and regenerates the document file. Fields are passed at the JSON root, without a `fields` wrapper.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `id` (path) | number | yes | Document ID, a positive integer. Documents of a record: [`GET /v1/crm-documents`](/docs/entities/documents/crm-list) |

## Request fields (body)

Pass at least one of the fields.

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `values` | object | no | Template field values. Keys are merged into the saved ones: keys missing from the request are kept. For example, `DocumentNumber` sets the document number |
| `stampsEnabled` | boolean | no | Turns stamps and signatures on or off. If the field is omitted, stamps are turned on. To keep them off, pass `stampsEnabled: false` in every request |

The request does not accept other fields, such as `title` or `templateId`. The stamps flag goes only at the body root, not inside `values`.

## Examples

### curl — personal key

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/crm-documents/1961" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "values": { "DocumentNumber": "VIBE-1" },
    "stampsEnabled": false
  }'
```

### curl — OAuth application

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/crm-documents/1961" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "values": { "DocumentNumber": "VIBE-1" },
    "stampsEnabled": false
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/crm-documents/1961', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    values: { DocumentNumber: 'VIBE-1' },
    stampsEnabled: false,
  }),
})

const { success, data } = await res.json()
console.log('New number:', data.number)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/crm-documents/1961', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    values: { DocumentNumber: 'VIBE-1' },
    stampsEnabled: false,
  }),
})

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

## Response fields

Returns the updated document. The full description of document fields is on the [Get a CRM document](/docs/entities/documents/crm-get) page.

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data.id` | string | Document ID |
| `data.number` | string | Document number after the update |
| `data.values` | object | Template field values after the update, together with service keys |
| `data.stampsEnabled` | boolean | Stamps flag the document was generated with |
| `data.updateTime` | string | Update time in ISO 8601 format |
| `data.updatedBy` | number | ID of the employee who updated the document. List: [`GET /v1/users`](/docs/entities/users) |
| `data.createTime` | string | In this method's response, the time the file was regenerated. The document creation date is returned by [`GET /v1/crm-documents/:id`](/docs/entities/documents/crm-get) |
| `data.createdBy` | null | `null` in this method's response. The creator is returned by [`GET /v1/crm-documents/:id`](/docs/entities/documents/crm-get) |
| `data.downloadUrlMachine` | string | [`/v1/crm-documents/:id/download`](/docs/entities/documents/download) URL for downloading the new DOCX. Requires `X-Api-Key` with the `crm` scope |

## Response example

Only the main fields are shown. Full list: [Get a CRM document](/docs/entities/documents/crm-get).

```json
{
  "success": true,
  "data": {
    "changeStampsEnabled": false,
    "downloadUrl": "https://example.bitrix24.com/bitrix/services/main/ajax.php?action=crm.documentgenerator.document.download&SITE_ID=s1&id=1961",
    "publicUrl": null,
    "title": "Addresses A463//10/2026",
    "number": "VIBE-1",
    "id": "1961",
    "createTime": "2026-10-08T17:57:43+00:00",
    "createdBy": null,
    "updateTime": "2026-10-08T17:57:42+00:00",
    "updatedBy": 1317,
    "stampsEnabled": false,
    "values": {
      "productsTableVariant": "",
      "stampsEnabled": false,
      "_creationMethod": "rest",
      "DocumentNumber": "VIBE-1"
    },
    "templateId": "87",
    "entityId": "8781",
    "entityTypeId": "2",
    "downloadUrlMachine": "https://vibecode.bitrix24.com/v1/crm-documents/1961/download"
  }
}
```

## Error response example

400 — the body has neither `values` nor `stampsEnabled`:

```json
{
  "success": false,
  "error": {
    "code": "MISSING_REQUIRED_FIELDS",
    "message": "values or stampsEnabled is required"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS` | `id` is not a positive integer. Message: `id must be a positive integer` |
| 400 | `MISSING_REQUIRED_FIELDS` | The body is `{}` or not a JSON object, for example an array. Message: `values or stampsEnabled is required` |
| 400 | `READONLY_FIELD` | The body has a field other than `values` and `stampsEnabled`, for example `title` |
| 400 | `INVALID_PARAMS` | `values` is not an object, `values` contains `stampsEnabled`, or `stampsEnabled` is not a boolean |
| 404 | `ENTITY_NOT_FOUND` | No document with this `id` exists, or it was deleted |
| 502 | `BITRIX_INVALID_RESPONSE` | Bitrix24 responded without the document or without the stamps flag |
| 403 | `BITRIX_ACCESS_DENIED` | No access to the CRM record the document is attached to, including when the record does not exist. Message: `Access denied` |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode |
| 403 | `SCOPE_DENIED` | The key lacks the `crm` scope |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |
| 401 | `TOKEN_MISSING` | The key has no tokens mapped to it — an OAuth application key was called without a user session |

Full list of common API errors — [Errors](/docs/errors).

## Known specifics

**The PDF and image are regenerated.** After an update, the DOCX, PDF and image are regenerated. Until they are ready, the [PDF](/docs/entities/documents/pdf) download responds with `409 DOCUMENT_NOT_READY`.

**The previous stamps value is not kept.** A request with only `values` generates the file with stamps, even if the document was created or updated by a previous request with `stampsEnabled: false`. The flag in [`GET /v1/crm-documents/:id`](/docs/entities/documents/crm-get) is not reliable for checking this. For details, see "Known specifics" on the [Get a CRM document](/docs/entities/documents/crm-get) page.

## See also

- [Get a CRM document](/docs/entities/documents/crm-get)
- [Create a CRM document](/docs/entities/documents/crm-create)
- [Delete a CRM document](/docs/entities/documents/crm-delete)
- [Documents by CRM record](/docs/entities/documents/crm-list)
- [Documents](/docs/entities/documents)
