## Replace managers

`PUT /v1/chats/:dialogId/managers`

Replaces the chat's entire list of managers with the given one: a manager missing from the list loses the role. The owner stays the owner whatever the list. To add managers without touching the others, use [Add managers](/docs/chats/members/managers-add).

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `dialogId` (path) | string | yes | Group chat identifier `chatXXX`. A personal dialog is refused |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `userIds` | number[] | yes | The managers after the call — from 1 to 50 chat member IDs. Each element is a positive integer: a number or a string of decimal digits without leading zeros or spaces, up to 2^53−1. Members: [`GET /v1/chats/:dialogId/users`](/docs/chats/members/list) |

Other body fields and any query parameters are rejected with `400 INVALID_PARAMS`.

## Examples

### curl — personal key

```bash
curl -X PUT "https://vibecode.bitrix24.com/v1/chats/chat42/managers" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "userIds": [7] }'
```

### curl — OAuth application

```bash
curl -X PUT "https://vibecode.bitrix24.com/v1/chats/chat42/managers" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "userIds": [7] }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/chat42/managers', {
  method: 'PUT',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ userIds: [7] }),
})

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

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/chat42/managers', {
  method: 'PUT',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ userIds: [7] }),
})

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

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | boolean | `true` — the list was saved |

## Response example

```json
{
  "success": true,
  "data": true
}
```

## Error response example

400 — an empty list:

```json
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "`userIds` is required: a non-empty array of Bitrix24 user ids. An empty list changes nothing on the portal — to remove managers use DELETE /v1/chats/:dialogId/managers?userIds=…."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_PARAMS` | `userIds` is absent, empty, not an array, longer than 50 or holds something other than a positive integer — the index and type are named in `message`; an extra body field or a query parameter; the body is not a JSON object. Checked before any call to Bitrix24 |
| 403 | `BITRIX_ACCESS_DENIED` | No right to change the managers, or `dialogId` is a personal dialog |
| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — see [access rights](/docs/access-rights) |
| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |
| 404 | `ENTITY_NOT_FOUND` | Bitrix24 returned "not found"; the portal code is in `error.b24Code` |
| 422 | `BITRIX_ERROR` | Bitrix24 did not save the list; the portal code is in `error.b24Code`. A list made only of users outside the chat lands here too: Bitrix24 answers with an internal error and changes nothing |
| 502 | `ME_ALIAS_RESOLUTION_FAILED` | The user could not be resolved for the `me` alias |

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

## Known specifics

**An empty list does not remove the managers.** Bitrix24 would accept it as a success and change nothing, so an empty `userIds` is rejected. To take the role away from everyone, pass their IDs to [Remove managers](/docs/chats/members/managers-remove).

**Users outside the chat are skipped** as long as the list holds at least one member: the others get the role, and the response is `true`.

## See also

- [Add managers](/docs/chats/members/managers-add)
- [Remove managers](/docs/chats/members/managers-remove)
- [Membership records](/docs/chats/members/relations)
- [Chat members](/docs/chats/members)
