
## Rename a chat

`PATCH /v1/chats/:chatId`

Changes the name of a group chat. The caller must be a member of the chat with permission to rename it.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `chatId` (path) | number | yes | Numeric chat ID. Get it from: [`POST /v1/chats`](/docs/chats/management/create) or the `chatId` field of a [`GET /v1/chats/recent`](/docs/chats/discovery/recent) row |
| `format` (query) | string | no | `v2` turns on the v2 mode — see "The v2 mode" below. Any other value is ignored and the response is unchanged |

**The v2 mode.** `format=v2` changes a group chat as a whole in one call: the name, description, avatar, owner, type, permissions, members and managers. The `title` field becomes optional, but at least one field is required. Every field is checked before any call to Bitrix24: an unknown field, a wrong type or a value outside the list is rejected with `400 INVALID_PARAMS` naming the field. The v2 mode requires the permission to change the chat — the owner has it by default — rather than the rename permission, which is enough without the parameter. A personal dialog is rejected with `422 BITRIX_ERROR` and `error.b24Code` `WRONG_MESSAGE_TYPE`. In the response, `data` is the object `{ result: true }`. To only rename a chat under the rename permission, call the endpoint without `format`.

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `title` | string | yes | New chat name. Cannot be empty. Optional in the v2 mode |
| `description` | string | no | The v2 mode only. New description |
| `avatar` | string \| number | no | The v2 mode only. An image as a base64 string, or the ID of a Drive file the caller can read |
| `ownerId` | number | no | The v2 mode only. Hand the chat over to this user — an ID from the [user list](/docs/entities/users/list) |
| `type` | string | no | The v2 mode only. Change the chat type. A change that is not allowed is rejected with `422 BITRIX_ERROR`, with the reason in `error.b24Code` |
| `searchable` | string | no | The v2 mode only. `Y` — an open chat: any employee can find it and join |
| `manageUi` | string | no | The v2 mode only. Who can change the name, description and avatar: `MEMBER`, `MANAGER`, `OWNER` |
| `manageUsersAdd` | string | no | The v2 mode only. Who can add members: `MEMBER`, `MANAGER`, `OWNER` |
| `manageUsersDelete` | string | no | The v2 mode only. Who can remove members: `MEMBER`, `MANAGER`, `OWNER` |
| `manageMessages` | string | no | The v2 mode only. Who can post: `NONE` (nobody but the owner), `MEMBER`, `MANAGER`, `OWNER` |
| `manageMessagesAutoDelete` | string | no | The v2 mode only. Who can turn on message auto-deletion: `NONE`, `MEMBER`, `MANAGER`, `OWNER` |
| `manageGuestInvites` | string | no | The v2 mode only. Who can invite guests: `NONE`, `MEMBER`, `MANAGER`, `OWNER` |
| `addedMemberEntities` | array | no | The v2 mode only. Members to add — `[type, id]` pairs: `["user", 5]`, `["department", "12:F"]` (a department with its sub-departments), `["project", 3]` |
| `deletedMemberEntities` | array | no | The v2 mode only. Members to remove — `[type, id]` pairs of the same form |
| `hideHistory` | string | no | The v2 mode only. `Y` — the added members do not see the earlier history |
| `addedManagers` | array | no | The v2 mode only. IDs of users to make managers — positive integers |
| `deletedManagers` | array | no | The v2 mode only. IDs of managers to remove the manager role from — positive integers |

## Examples

### curl — personal key

```bash
curl -X PATCH https://vibecode.bitrix24.com/v1/chats/3663 \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Project Beta"
  }'
```

### curl — OAuth application

```bash
curl -X PATCH https://vibecode.bitrix24.com/v1/chats/3663 \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Project Beta"
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/3663', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    title: 'Project Beta',
  }),
})

const { success, data } = await res.json()
console.log('Renamed:', data) // true
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/3663', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    title: 'Project Beta',
  }),
})

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

### curl — the v2 mode

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/chats/3663?format=v2" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "Release discussion",
    "addedManagers": [27],
    "manageMessages": "MANAGER"
  }'
```

## Response fields

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data` | boolean | `true` when the rename succeeded |
| `data.result` | boolean | The v2 mode: `true` — the changes are applied |

## Response example

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

## Error response example

400 — an empty title was passed:

```json
{
  "success": false,
  "error": {
    "code": "TITLE_EMPTY",
    "message": "title is required and cannot be blank."
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 400 | `INVALID_CHAT_ID` | `chatId` is not a positive integer |
| 400 | `TITLE_EMPTY` | The `title` field is missing or empty. Without `format` only |
| 400 | `INVALID_PARAMS` | The v2 mode only: no field to change, the body is not a JSON object, an unknown field or a query string parameter other than `format`, a wrong type or a value outside the list — the message names the field. Checked before any call to Bitrix24 |
| 404 | `CHAT_NOT_FOUND_OR_NO_ACCESS` | The chat does not exist or the caller has no permission to rename it. Without `format` only |
| 404 | `ENTITY_NOT_FOUND` | The v2 mode: Bitrix24 returned "not found". The Bitrix24 code is in `error.b24Code` |
| 422 | `BITRIX_ERROR` | Bitrix24 returned an error. The Bitrix24 code is in `error.b24Code`. The v2 mode: a missing chat lands here with `CHAT_NOT_FOUND`, a personal dialog with `WRONG_MESSAGE_TYPE`. Without `format`: a collab chat lands here with `ACCESS_ERROR` and the text `This chat cannot be renamed` |
| 403 | `BITRIX_ACCESS_DENIED` | The v2 mode: the caller has no permission to change the chat — Bitrix24 refused with the `ACCESS_DENIED` code. The same error is returned for a collab chat, even to its owner |
| 403 | `SCOPE_DENIED` | The API key lacks the `im` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — the call changes the chat |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |

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

## Known specifics

**An avatar in the request body.** The request body is limited to 1 MiB, and base64 inflates an image by a third: the `avatar` field fits an image of up to about 750 KiB. Upload a larger image to Drive and pass the file ID.

## See also

- [Chat management](/docs/chats/management)
- [Transfer chat ownership](/docs/chats/management/owner)
- [Add members](/docs/chats/members/add)
