[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-chats\u002Fmanagement\u002Favatar":3,"docs-tabs-chats\u002Fmanagement\u002Favatar":6},{"content":4,"lastmod":5},"## Change a chat avatar\n\n`PUT \u002Fv1\u002Fchats\u002F:dialogId\u002Favatar`\n\nSets the chat avatar: an image from the request body or a file that is already on Drive. A body field selects the mode.\n\n## Parameters\n\n| Parameter | Type | Required | Description |\n|----------|-----|:-----:|---------|\n| `dialogId` (path) | string | yes | Dialog ID: `chatXXX` for a group chat, a numeric user ID for private messages, `me` — the current user's personal dialog. A CRM entity chat is found via [Find a CRM entity chat](\u002Fdocs\u002Fchats\u002Fdiscovery\u002Ffind) |\n\nThe endpoint takes no query parameters: any parameter in the query string is refused with `400 INVALID_PARAMS`.\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|---------|\n| `avatar` | string | no | A PNG, JPEG, GIF or WebP image in base64, with sides of at most 5000 pixels. The string must not contain spaces or line breaks. A `data:image\u002F\u003Ctype>;base64,` prefix is allowed and is stripped. The whole request body is limited to 1 MiB, which is about 750 KiB of the source file |\n| `avatarId` | number | no | The `fileId` of a file on Drive — the `data.fileId` field of the [Get file](\u002Fdocs\u002Fentities\u002Ffiles\u002Fget) response, not `data.id` |\n\nSend exactly one of the two fields. A body with neither, with both, or with other fields is refused with `400 INVALID_PARAMS`.\n\n## Examples\n\nThe examples set the avatar from the local file `logo.png`.\n\n### curl — personal key\n\n```bash\n{ printf '{\"avatar\":\"'; base64 \u003C logo.png | tr -d '\\r\\n'; printf '\"}'; } | \\\ncurl -X PUT https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2741\u002Favatar \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  --data-binary @-\n```\n\n### curl — OAuth application\n\n```bash\n{ printf '{\"avatar\":\"'; base64 \u003C logo.png | tr -d '\\r\\n'; printf '\"}'; } | \\\ncurl -X PUT https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2741\u002Favatar \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  --data-binary @-\n```\n\n### JavaScript — personal key\n\n```javascript\nimport { readFileSync } from 'node:fs'\n\nconst avatar = readFileSync('logo.png').toString('base64')\n\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2741\u002Favatar', {\n  method: 'PUT',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ avatar }),\n})\n\nconst { data } = await res.json()\nconsole.log('Image ID:', data.avatarId)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nimport { readFileSync } from 'node:fs'\n\nconst avatar = readFileSync('logo.png').toString('base64')\n\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fchat2741\u002Favatar', {\n  method: 'PUT',\n  headers: {\n    'X-Api-Key': 'YOUR_APP_KEY',\n    'Authorization': 'Bearer USER_SESSION_TOKEN',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ avatar }),\n})\n\nconst { data } = await res.json()\nconsole.log('Image ID:', data.avatarId)\n```\n\nFor a file on Drive, the request body is `{\"avatarId\": 830}`, with the same headers.\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data.avatarId` | number | Only in the `avatar` mode: the ID of the image Bitrix24 saved as the avatar |\n| `data.result` | boolean | Only in the `avatarId` mode: `true` — the avatar is set |\n\n## Response example\n\nAn image from the request body, the `avatar` field:\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"avatarId\": 828\n  }\n}\n```\n\nA file on Drive, the `avatarId` field:\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"result\": true\n  }\n}\n```\n\n## Error response example\n\n422 — `avatarId` carries the Drive file's `id` instead of its `fileId`:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"BITRIX_ERROR\",\n    \"message\": \"Wrong file type\",\n    \"b24Code\": \"WRONG_PARAMETER\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `INVALID_PARAMS` | Neither `avatar` nor `avatarId` is sent, or both are |\n| 400 | `INVALID_PARAMS` | `avatar` is not a string |\n| 400 | `INVALID_PARAMS` | `avatar` is not base64: an empty string, a length that is not a multiple of 4, characters outside the base64 alphabet, spaces or line breaks |\n| 400 | `INVALID_PARAMS` | `avatar` does not decode to a PNG, JPEG, GIF or WebP image |\n| 400 | `INVALID_PARAMS` | An image side exceeds 5000 pixels |\n| 400 | `INVALID_PARAMS` | `avatarId` is not a positive integer |\n| 400 | `INVALID_PARAMS` | The body has a field other than `avatar` and `avatarId` |\n| 400 | `INVALID_PARAMS` | The request body is not a JSON object |\n| 400 | `INVALID_PARAMS` | The query string has a parameter |\n| 413 | `PAYLOAD_TOO_LARGE` | The request body exceeds 1 MiB |\n| 403 | `BITRIX_ACCESS_DENIED` | Bitrix24 refused: the user is not a chat member, or the `ui` permission does not let them change the avatar. The same error is returned for a collab chat, even to its owner |\n| 422 | `BITRIX_ERROR` | `error.b24Code` is `WRONG_PARAMETER` with the text `Wrong file type`: `avatarId` is not the `fileId` of a Drive file — the file's `data.id` was sent, or no file has that `fileId` |\n| 422 | `BITRIX_ERROR` | Bitrix24 returned another error; the portal code is in `error.b24Code`. If the chat does not exist, the code is `CHAT_NOT_FOUND` |\n| 403 | `SCOPE_DENIED` | The API key lacks the `im` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — changing the avatar counts as a write |\n| 401 | `TOKEN_MISSING` | The API key has no configured Bitrix24 tokens |\n| 502 | `ME_ALIAS_RESOLUTION_FAILED` | `dialogId=me` — the current user's ID could not be resolved |\n| 502 | `BITRIX_UNAVAILABLE` | Bitrix24 is unavailable or returned a server error |\n\nAll `400` refusals happen before the Bitrix24 call.\n\nFull list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**The image is checked before the write.** Bitrix24 would accept a string that does not read as an image and report success, but it would remove the chat avatar. So the format and size are checked before the Bitrix24 call: a failed check returns `400 INVALID_PARAMS`, and the previous avatar stays.\n\n**A system message about the avatar change.** Changing the avatar in either mode posts a system message to the chat saying that the user changed the chat icon.\n\n**Current avatar.** The current avatar comes in the `avatar` field of the [Dialog details](\u002Fdocs\u002Fchats\u002Fdiscovery\u002Fget) response. An empty string means the chat has no avatar.\n\n## See also\n\n- [Change a chat color](\u002Fdocs\u002Fchats\u002Fmanagement\u002Fcolor)\n- [Change a chat description](\u002Fdocs\u002Fchats\u002Fmanagement\u002Fdescription)\n- [Set the permission to change chat appearance](\u002Fdocs\u002Fchats\u002Fmanagement\u002Fpermissions-ui)\n- [Get file](\u002Fdocs\u002Fentities\u002Ffiles\u002Fget)\n- [Upload file](\u002Fdocs\u002Fentities\u002Ffiles\u002Fupload)\n","2026-10-19",{},1794739538733]