## Add a product to a deal

`POST /v1/deals/:id/products`

Adds a single product row to a deal. Unlike `PUT /v1/deals/:id/products`, it does not replace existing rows.

> **Field names are validated.** A field name that is not in the writable set is not dropped silently: the request is rejected with `400 INVALID_PARAMS` and the error text lists the writable names. Read-only fields that appear in product-row responses — `priceAccount`, `ownerId`, `storeId` and others — are accepted and ignored, so an object read via `GET` can be sent back as is.

## Parameters

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

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `productId` | number | no | Catalog product ID. If set without `productName`, the name is taken from the catalog. Catalog: [`GET /v1/products`](/docs/entities/products/list). With neither `productId` nor `productName`, the row is created with no product and an empty name |
| `productName` | string | no | Row name — for a free-text row with no catalog product |
| `price` | number | no | Unit price. Without it the row is created with a zero price |
| `quantity` | number | no | Quantity. Without it the row is created with a quantity of `1` |
| `discountTypeId` | number | no | How the discount is set: `1` — as an amount in `discount`, `2` — as a percentage in `discountRate`. Defaults to `2` |
| `discount` | number | no | Discount amount. Applied only when `discountTypeId` is `1` |
| `discountRate` | number | no | Discount percentage. Applied only when `discountTypeId` is `2` |
| `taxRate` | number | no | Tax rate (%) |
| `taxIncluded` | boolean | no | Tax included in the price |
| `measureCode` | number | no | Unit of measure code, for example `796` — piece. List: [`GET /v1/catalog-measures`](/docs/entities/catalog-measures/list) |
| `sort` | number | no | Sort order |

## Examples

### curl — personal key

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/deals/8821/products" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "productId": 6967, "price": 25000, "quantity": 2 }'
```

### curl — OAuth application

```bash
curl -X POST "https://vibecode.bitrix24.com/v1/deals/8821/products" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "productId": 6967, "price": 25000, "quantity": 2 }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/deals/8821/products', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ productId: 6967, price: 25000, quantity: 2 }),
})

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

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/deals/8821/products', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ productId: 6967, price: 25000, quantity: 2 }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | object | The created product row in full, HTTP status `201`. Row fields — see [Product fields](/docs/entities/deals/products-fields) |

## Response example

```json
{
  "success": true,
  "data": {
    "id": 2381,
    "ownerId": 8821,
    "ownerType": "D",
    "productId": 6967,
    "productName": "Parent product",
    "price": 25000,
    "priceAccount": 25000,
    "priceExclusive": 25000,
    "priceNetto": 25000,
    "priceBrutto": 25000,
    "quantity": 2,
    "discountTypeId": 2,
    "discountRate": 0,
    "discount": 0,
    "taxIncluded": false,
    "customized": "Y",
    "measureCode": 796,
    "measureName": "pcs",
    "sort": 0,
    "xmlId": "sale_basket_1403",
    "type": 3,
    "storeId": null
  }
}
```

## Error response example

404 — no deal with this `id`:

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

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS` | The body contains a field name that is not among the writable fields — see [Product fields](/docs/entities/deals/products-fields) |
| 400 | `INVALID_PARAMS` | The body carries no writable product-row field — an empty object, or read-only fields only. The error text lists the writable names |
| 404 | `ENTITY_NOT_FOUND` | Deal not found. The message is `Owner was not found` |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — see [access rights](/docs/access-rights) |
| 403 | `SCOPE_DENIED` | API key lacks the `crm` scope |
| 401 | `TOKEN_MISSING` | API key has no configured tokens |

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

## See also

- [Product rows](/docs/entities/deals/products-get)
- [Set products](/docs/entities/deals/products-set)
- [Delete a product](/docs/entities/deals/products-delete)
- [CRM products](/docs/entities/products)
