
## Set lead products

`PUT /v1/leads/:id/products`

Sets the lead product lines. Fully replaces the current list — pass all the lines you need.

## Request fields (body)

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `items` | array | yes | Array of product lines |
| `items[].productId` | number | yes | Product ID. Catalog: `GET /v1/products` |
| `items[].price` | number | yes | Unit price |
| `items[].quantity` | number | yes | Quantity |
| `items[].discount` | number | no | Discount amount |
| `items[].taxRate` | number | no | Tax rate (%) |
| `items[].taxIncluded` | boolean | no | Tax included in price |

## Examples

### curl — personal key

```bash
curl -X PUT "https://vibecode.bitrix24.com/v1/leads/312/products" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      { "productId": 1, "price": 25000, "quantity": 2 },
      { "productId": 5, "price": 5000, "quantity": 1, "discount": 500 }
    ]
  }'
```

### curl — OAuth application

```bash
curl -X PUT "https://vibecode.bitrix24.com/v1/leads/312/products" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      { "productId": 1, "price": 25000, "quantity": 2 },
      { "productId": 5, "price": 5000, "quantity": 1, "discount": 500 }
    ]
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/leads/312/products', {
  method: 'PUT',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    items: [
      { productId: 1, price: 25000, quantity: 2 },
      { productId: 5, price: 5000, quantity: 1, discount: 500 },
    ],
  }),
})

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

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/leads/312/products', {
  method: 'PUT',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    items: [
      { productId: 1, price: 25000, quantity: 2 },
      { productId: 5, price: 5000, quantity: 1, discount: 500 },
    ],
  }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `data` | array | Array of the resulting product lines with the fields productId, productName, price, quantity, discount, taxRate, taxIncluded |

Array of the resulting product lines with the fields `productId`, `productName`, `price`, `quantity`, `discount`, `taxRate`, `taxIncluded`.

## Response example

```json
{
  "success": true,
  "data": [
    {
      "productId": 1,
      "productName": "Server hardware",
      "price": 25000,
      "quantity": 2,
      "discount": 0,
      "taxRate": null,
      "taxIncluded": false
    },
    {
      "productId": 5,
      "productName": "Installation and setup",
      "price": 5000,
      "quantity": 1,
      "discount": 500,
      "taxRate": null,
      "taxIncluded": false
    }
  ]
}
```

## Error response example

400 — invalid format:

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "items must be an array"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS` | `items` is not an array |
| 404 | `ENTITY_NOT_FOUND` | Lead not found |
| 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).

## Known specifics

**Full replacement:** PUT replaces the entire product list. To add a line — first fetch the current ones (`GET`), add the new one to the array, and send everything (`PUT`).

## See also

- [Product lines](/docs/entities/leads/products-get)
- [Get lead](/docs/entities/leads/get)
- [Catalog products](/docs/entities/products)
- [Limits and optimization](/docs/optimization)
