## Update an inventory document item

`PATCH /v1/catalog-document-elements/:id`

Changes an inventory document item.

Pass only the fields you change, flat at the JSON root, without a `fields` wrapper.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `id` (path) | number | yes | Item ID. List: [`GET /v1/catalog-document-elements`](/docs/entities/catalog-document-elements/list) |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `amount` | number | no | Product quantity |
| `purchasingPrice` | number | no | Purchase price per unit |
| `storeFrom` | number | no | Source warehouse. List: [`GET /v1/warehouses`](/docs/entities/warehouses/list). Which warehouse a document needs depends on its type — see [inventory document items](/docs/entities/catalog-document-elements) |
| `storeTo` | number | no | Destination warehouse. List: [`GET /v1/warehouses`](/docs/entities/warehouses/list) |
| `docId` | number | no | RO. Set only on creation. List: [`GET /v1/catalog-documents`](/docs/entities/catalog-documents/list) |
| `elementId` | number | no | RO. Set only on creation. List: [`GET /v1/catalog-products`](/docs/entities/catalog-products/list) |
| `id` | number | no | RO. The item ID is passed in the path |

## Examples

### curl — personal key

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/catalog-document-elements/33" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 5
  }'
```

### curl — OAuth application

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/catalog-document-elements/33" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": 5
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-document-elements/33', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    amount: 5,
  }),
})

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

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-document-elements/33', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    amount: 5,
  }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | `true` on successful update |
| `data.id` | number | Item ID |
| `data.docId` | number | Document ID. Document — [`GET /v1/catalog-documents/:id`](/docs/entities/catalog-documents/get) |
| `data.elementId` | number | Product ID. Product — [`GET /v1/catalog-products/:id`](/docs/entities/catalog-products/get) |
| `data.amount` | number \| null | Product quantity. `null` if not set |
| `data.purchasingPrice` | number \| null | Purchase price per unit. `null` if not set |
| `data.storeFrom` | number \| null | Source warehouse. `null` if not set. Warehouses — [`GET /v1/warehouses`](/docs/entities/warehouses/list) |
| `data.storeTo` | number \| null | Destination warehouse. `null` if not set. Warehouses — [`GET /v1/warehouses`](/docs/entities/warehouses/list) |
| `meta.warnings` | array | Present only if the body contains a field that is not among the item fields. Each element contains `code: "UNRECOGNIZED_WRITE_FIELD"`, `field` with the field name, and `message`. On a route that wraps the field map itself, an object under `fields` is rejected with `400 NESTED_FIELDS_ENVELOPE` when the schema does not declare `fields`; pass fields flat at the JSON root. |

## Response example

```json
{
  "success": true,
  "data": {
    "amount": 5,
    "docId": 299,
    "elementId": 6595,
    "id": 33,
    "purchasingPrice": 11000,
    "storeFrom": null,
    "storeTo": 11
  }
}
```

## Error response example

422 — the item's document is conducted:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Conducted document",
    "b24Code": "ERROR_DOCUMENT_STATUS"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 422 | `BITRIX_ERROR` | The item's document is conducted. Message `Conducted document`, `b24Code` — `ERROR_DOCUMENT_STATUS`. First [cancel conducting](/docs/entities/catalog-documents/cancel) |
| 404 | `ENTITY_NOT_FOUND` | No item with the given `id` |
| 400 | `READONLY_FIELD` | The body contains `docId`, `elementId`, or `id`. The message names the field: `Field 'docId' is read-only and cannot be set` |
| 400 | `EMPTY_UPDATE_BODY` | The request body is empty |
| 400 | `NO_RECOGNIZED_UPDATE_FIELDS` | The body contains no updatable field, for example the fields are wrapped in `fields` |
| 400 | `INVALID_PARAMS` | `id` in the path is not a non-negative integer |
| 400 | `INVALID_PARAMS` | A field value has the wrong type: a non-numeric string in a numeric field, for example `"amount": "abc"`, or an object or array instead of a number or string. The field name is in `error.message` |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key works in read-only mode |
| 403 | `SCOPE_DENIED` | The API key does not have the `catalog` scope |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header was not passed |
| 401 | `INVALID_API_KEY` | The passed API key was not found |

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

## See also

- [Get an item](/docs/entities/catalog-document-elements/get)
- [Create an item](/docs/entities/catalog-document-elements/create)
- [Delete an item](/docs/entities/catalog-document-elements/delete)
- [Item fields](/docs/entities/catalog-document-elements/fields)
- [Cancel conducting](/docs/entities/catalog-documents/cancel)
- [Batch](/docs/batch)
