## Replace clients of a wait list record

`PUT /v1/booking-wait-list/:id/clients`

Writes the passed set as the clients of a wait list record: clients missing from the request are removed from the record. An empty `clients` array removes all clients.

## Parameters

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

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|----------|
| `clients` | array | yes | New set of the record's clients. An empty array removes all clients |
| `clients[].id` | number | yes | CRM contact or company ID. Lists: [`GET /v1/contacts`](/docs/entities/contacts/list), [`GET /v1/companies`](/docs/entities/companies/list) |
| `clients[].type.module` | string | yes | Client type module: `crm`. Dictionary: [`GET /v1/booking-client-types`](/docs/entities/booking-client-types) |
| `clients[].type.code` | string | yes | Client type code: `CONTACT` — contact, `COMPANY` — company. Dictionary: [`GET /v1/booking-client-types`](/docs/entities/booking-client-types) |

The body accepts no other fields: an extra field returns `400 INVALID_PARAMS`.

## Examples

### curl — personal key

```bash
curl -X PUT "https://vibecode.bitrix24.com/v1/booking-wait-list/37/clients" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "clients": [
      { "id": 3013, "type": { "module": "crm", "code": "CONTACT" } },
      { "id": 3149, "type": { "module": "crm", "code": "COMPANY" } }
    ]
  }'
```

### curl — OAuth application

```bash
curl -X PUT "https://vibecode.bitrix24.com/v1/booking-wait-list/37/clients" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "clients": [
      { "id": 3013, "type": { "module": "crm", "code": "CONTACT" } },
      { "id": 3149, "type": { "module": "crm", "code": "COMPANY" } }
    ]
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/booking-wait-list/37/clients', {
  method: 'PUT',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    clients: [
      { id: 3013, type: { module: 'crm', code: 'CONTACT' } },
      { id: 3149, type: { module: 'crm', code: 'COMPANY' } },
    ],
  }),
})

const { success, data } = await res.json()
console.log('Record clients:', data.map((client) => `${client.type.code} ${client.id}`))
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/booking-wait-list/37/clients', {
  method: 'PUT',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    clients: [
      { id: 3013, type: { module: 'crm', code: 'CONTACT' } },
      { id: 3149, type: { module: 'crm', code: 'COMPANY' } },
    ],
  }),
})

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

## Response fields

The response contains the clients of the wait list record, read again after writing.

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | `true` on success |
| `data` | array | The record's clients after the replacement. After an empty `clients`, an empty array |
| `data[].id` | number | CRM contact or company ID. Get: [`GET /v1/contacts/:id`](/docs/entities/contacts/get), [`GET /v1/companies/:id`](/docs/entities/companies/get) |
| `data[].type.code` | string | Client type code: `CONTACT` — contact, `COMPANY` — company |
| `data[].type.module` | string | Client type module: `crm` |

## Response example

```json
{
  "success": true,
  "data": [
    {
      "id": 3013,
      "type": {
        "code": "CONTACT",
        "module": "crm"
      }
    },
    {
      "id": 3149,
      "type": {
        "code": "COMPANY",
        "module": "crm"
      }
    }
  ]
}
```

## Error response example

400 — the client type is not in the dictionary:

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "Client type not found"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 400 | `INVALID_PARAMS` | `Client type not found` — the `type.module` and `type.code` pair is not in the [client type dictionary](/docs/entities/booking-client-types). The record's clients stay unchanged |
| 400 | `INVALID_PARAMS` | `Each client requires id and type.module/type.code` — a `clients` item has no `id`, `type.module` or `type.code`, or its `id` is not a positive integer |
| 400 | `INVALID_PARAMS` | `Only clients can be written` — the body contains a field other than `clients` |
| 400 | `INVALID_PARAMS` | `id must be a canonical positive safe integer` — the record `id` is not a positive integer |
| 400 | `MISSING_REQUIRED_FIELDS` | `clients must be an array` — the body has no `clients`, or it is not an array |
| 404 | `ENTITY_NOT_FOUND` | `Booking record not found` — no wait list record with this `id` |
| 404 | `ENTITY_NOT_FOUND` | No CRM contact or company with the given `clients[].id`. The record's clients stay unchanged |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is missing |
| 401 | `TOKEN_MISSING` | The key has no Bitrix24 tokens |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only. The request is rejected before any call to Bitrix24 |
| 403 | `SCOPE_DENIED` | The key does not have the `booking` scope |
| 429 | `RATE_LIMITED` | Request rate exceeded. The effective cap is in the `x-ratelimit-limit` header |
| 502 | `BITRIX_RESPONSE_INVALID` | `Bitrix24 did not confirm the booking operation` — Bitrix24 did not confirm the write |
| 502 | `BITRIX_RESPONSE_INVALID` | `Bitrix24 returned an unexpected booking response` — Bitrix24 returned a client list of an unexpected shape |

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

## See also

- [Wait list clients](/docs/entities/booking-wait-list/clients)
- [List clients of a wait list record](/docs/entities/booking-wait-list/clients-list)
- [Remove clients from a wait list record](/docs/entities/booking-wait-list/clients-delete)
- [Booking client types](/docs/entities/booking-client-types)
- [List contacts](/docs/entities/contacts/list)
- [List companies](/docs/entities/companies/list)
