## Create an inventory document item

`POST /v1/catalog-document-elements`

Adds an item to an inventory document.

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

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `docId` | number | yes | Document ID. List: [`GET /v1/catalog-documents`](/docs/entities/catalog-documents/list). Cannot be changed after creation |
| `elementId` | number | yes | Product ID. List: [`GET /v1/catalog-products`](/docs/entities/catalog-products/list). Cannot be changed after creation |
| `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) |

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/catalog-document-elements" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "docId": 299,
    "elementId": 6595,
    "amount": 3,
    "purchasingPrice": 11000,
    "storeTo": 11
  }'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/catalog-document-elements" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "docId": 299,
    "elementId": 6595,
    "amount": 3,
    "purchasingPrice": 11000,
    "storeTo": 11
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-document-elements', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    docId: 299,
    elementId: 6595,
    amount: 3,
    purchasingPrice: 11000,
    storeTo: 11,
  }),
})

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

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/catalog-document-elements', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    docId: 299,
    elementId: 6595,
    amount: 3,
    purchasingPrice: 11000,
    storeTo: 11,
  }),
})

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

## Response fields

HTTP status `201 Created`.

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | `true` on successful creation |
| `data.id` | number | ID of the created item |
| `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 passed |
| `data.purchasingPrice` | number \| null | Purchase price per unit. `null` if not passed |
| `data.storeFrom` | number \| null | Source warehouse. `null` if not passed. Warehouses — [`GET /v1/warehouses`](/docs/entities/warehouses/list) |
| `data.storeTo` | number \| null | Destination warehouse. `null` if not passed. 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 has `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": 3,
    "docId": 299,
    "elementId": 6595,
    "id": 33,
    "purchasingPrice": 11000,
    "storeFrom": null,
    "storeTo": 11
  }
}
```

## Error response example

404 — no document with the given `docId`:

```json
{
  "success": false,
  "error": {
    "code": "ENTITY_NOT_FOUND",
    "message": "Document not found"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 404 | `ENTITY_NOT_FOUND` | No document with the given `docId`. Message — `Document not found` |
| 400 | `MISSING_REQUIRED_FIELDS` | A required field was not passed. The message names it: `Body field "elementId" is required to create catalogDocumentElement.` |
| 400 | `READONLY_FIELD` | The body contains `id`, a read-only field |
| 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` |
| 422 | `BITRIX_ERROR` | The document is conducted. Message `Conducted document`, `b24Code` — `ERROR_DOCUMENT_STATUS`. First [cancel conducting](/docs/entities/catalog-documents/cancel) |
| 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

- [List items](/docs/entities/catalog-document-elements/list)
- [Update an item](/docs/entities/catalog-document-elements/update)
- [Delete an item](/docs/entities/catalog-document-elements/delete)
- [Item fields](/docs/entities/catalog-document-elements/fields)
- [Create an inventory document](/docs/entities/catalog-documents/create)
- [Conduct a document](/docs/entities/catalog-documents/conduct)
- [Batch](/docs/batch)
