[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-chats\u002Fmessages\u002Fblocks-update":3,"docs-tabs-chats\u002Fmessages\u002Fblocks-update":6},{"content":4,"lastmod":5},"## Replace a block of a message\n\n`PATCH \u002Fv1\u002Fchats\u002Fmessages\u002F:messageId\u002Fblocks\u002F:blockId`\n\nReplaces a block of a constructor message entirely.\n\n## Parameters\n\n| Parameter | Type | Required | Default | Description |\n|----------|-----|:-----:|-----------|---------|\n| `messageId` (path) | number | yes | — | ID of the constructor message, a positive integer — `data.id` of the [v2 send](\u002Fdocs\u002Fchats\u002Fmessages\u002Fsend) response or the `id` of a message with a non-null `block` in [Messages around a message](\u002Fdocs\u002Fchats\u002Fmessages\u002Fcontext) |\n| `blockId` (path) | string | yes | — | Block ID — the value of `block.elements[].id` of the message. Blocks of a message — [Messages around a message](\u002Fdocs\u002Fchats\u002Fmessages\u002Fcontext) |\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|------|-----|:-----:|---------|\n| `element` | object | yes | The new block in the Bitrix24 constructor format: `type` and the fields of that type, for example `{ \"type\": \"text\", \"text\": \"Build failed\" }` |\n\nOther body fields and query parameters are rejected with `400 INVALID_PARAMS`.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X PATCH \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fmessages\u002F1001\u002Fblocks\u002F650a1b2c3d4e5\" \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{ \"element\": { \"type\": \"text\", \"text\": \"Build failed\" } }'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X PATCH \"https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fmessages\u002F1001\u002Fblocks\u002F650a1b2c3d4e5\" \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{ \"element\": { \"type\": \"text\", \"text\": \"Build failed\" } }'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fmessages\u002F1001\u002Fblocks\u002F650a1b2c3d4e5', {\n  method: 'PATCH',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({ element: { type: 'text', text: 'Build failed' } }),\n})\n\nconst { data } = await res.json()\nconsole.log('Block replaced:', data.result)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002Fmessages\u002F1001\u002Fblocks\u002F650a1b2c3d4e5', {\n  method: 'PATCH',\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({ element: { type: 'text', text: 'Build failed' } }),\n})\n\nconst { data } = await res.json()\nconsole.log('Block replaced:', data.result)\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | Always `true` on success |\n| `data.result` | boolean | `true` — the block was replaced |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": { \"result\": true }\n}\n```\n\n## Error response example\n\n422 — there is no block with this ID:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"BITRIX_ERROR\",\n    \"message\": \"ELEMENT_NOT_FOUND\",\n    \"b24Code\": \"ELEMENT_NOT_FOUND\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `INVALID_PARAMS` | `messageId` is not a positive integer, the body is not a JSON object, `element` is missing or not an object, or an extra body field or a query parameter is passed. Checked before any call to Bitrix24 |\n| 404 | `ENTITY_NOT_FOUND` | Bitrix24 returned a generic \"not found\" code or an error with the text \"not found\". The portal code is in `error.b24Code` |\n| 422 | `BITRIX_ERROR` | Bitrix24 returned an error, the portal code is in `error.b24Code`. `MESSAGE_NOT_FOUND` — there is no message with this ID, `BLOCK_NOT_FOUND` — the message has no blocks, `ELEMENT_NOT_FOUND` — there is no block with this ID, `WRONG_ELEMENT_TYPE` and `EMPTY_TEXT_FIELD` — the block is malformed, `BLOCK_LENGTH_EXCEEDED` — the message blocks exceed the length limit, `MESSAGE_ACCESS_DENIED` — you have no permission to edit the message, for example it belongs to someone else |\n| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — see [access rights](\u002Fdocs\u002Faccess-rights) |\n| 401 | `TOKEN_MISSING` | The API key has no Bitrix24 tokens configured |\n\nThe full list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**`element.id` does not change the block ID.** The block keeps the ID from the path, even if a different one is passed in `element.id`.\n\n**Only constructor messages have blocks.** A message becomes a constructor message when it is sent with the `block` field in [v2 send mode](\u002Fdocs\u002Fchats\u002Fmessages\u002Fsend) or when blocks are set on it by [editing the message](\u002Fdocs\u002Fchats\u002Fmessages\u002Fupdate) in v2 mode. A plain message has no blocks.\n\n## See also\n\n- [Add a block to a message](\u002Fdocs\u002Fchats\u002Fmessages\u002Fblocks-create)\n- [Remove a block from a message](\u002Fdocs\u002Fchats\u002Fmessages\u002Fblocks-delete)\n- [Messages around a message](\u002Fdocs\u002Fchats\u002Fmessages\u002Fcontext)\n- [Edit a message](\u002Fdocs\u002Fchats\u002Fmessages\u002Fupdate)\n","2026-10-05",{},1795344016606]