[{"data":1,"prerenderedAt":7},["ShallowReactive",2],{"docs-chats\u002Ffiles\u002Fupload-publish":3,"docs-tabs-chats\u002Ffiles\u002Fupload-publish":6},{"content":4,"lastmod":5},"## Publish uploaded files\n\n`POST \u002Fv1\u002Fchats\u002F:chatId\u002Ffiles\u002Fuploads\u002Fpublish`\n\nCreates one message with previously uploaded files. `uploadIds` contains IDs from the upload route responses. Repeating the call after an unknown outcome can create a second message: the client needs its own idempotency ledger.\n\n## Parameters\n\n| Parameter | Type | Required | Description |\n|-----------|------|:--------:|-------------|\n| `chatId` (path) | number | yes | Chat ID |\n\n## Request fields (body)\n\n| Field | Type | Required | Description |\n|-------|------|:--------:|-------------|\n| `uploadIds` | number[] | yes | 1 to 10 positive uploaded file IDs. Get them: `data.file.id` in the response of [Upload a file to a chat folder](\u002Fdocs\u002Fchats\u002Ffiles\u002Fupload-to-folder) |\n| `message` | string | no | Caption |\n| `replyId` | number | no | Message ID to reply to |\n| `asFile` | boolean | no | Send as a file |\n| `templateId` | string | no | Template ID |\n| `copilot` | object | no | CoPilot parameters for the message. Passed unchanged; supported in CoPilot chats |\n\nRequires the `im` scope and a write-enabled key. Other fields and query parameters are rejected with `400 INVALID_PARAMS`.\n\nThe `message` text is limited to 20000 Unicode code points. The complete outgoing string is counted, including markup, URLs and mentions, without truncation or trimming. For example, `😀` is one code point, while a compound emoji may occupy several. The request is rejected before any call to Bitrix24.\n\nIf the caption exceeds the length limit, `uploadIds` remain available for publication with a corrected caption.\n\n## Examples\n\n### curl — personal key\n\n```bash\ncurl -X POST https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002F42\u002Ffiles\u002Fuploads\u002Fpublish \\\n  -H \"X-Api-Key: YOUR_API_KEY\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"uploadIds\":[7701],\"message\":\"Caption\"}'\n```\n\n### curl — OAuth application\n\n```bash\ncurl -X POST https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002F42\u002Ffiles\u002Fuploads\u002Fpublish \\\n  -H \"X-Api-Key: YOUR_APP_KEY\" \\\n  -H \"Authorization: Bearer USER_SESSION_TOKEN\" \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -d '{\"uploadIds\":[7701],\"message\":\"Caption\"}'\n```\n\n### JavaScript — personal key\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002F42\u002Ffiles\u002Fuploads\u002Fpublish', {\n  method: 'POST',\n  headers: {\n    'X-Api-Key': 'YOUR_API_KEY',\n    'Content-Type': 'application\u002Fjson',\n  },\n  body: JSON.stringify({\"uploadIds\": [7701], \"message\": \"Caption\"}),\n})\nconst { success, data, error } = await res.json()\nconsole.log(success ? data : error)\n```\n\n### JavaScript — OAuth application\n\n```javascript\nconst res = await fetch('https:\u002F\u002Fvibecode.bitrix24.com\u002Fv1\u002Fchats\u002F42\u002Ffiles\u002Fuploads\u002Fpublish', {\n  method: 'POST',\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({\"uploadIds\": [7701], \"message\": \"Caption\"}),\n})\nconst { success, data, error } = await res.json()\nconsole.log(success ? data : error)\n```\n\n## Response fields\n\n| Field | Type | Description |\n|------|-----|---------|\n| `success` | boolean | `true` on success |\n| `data.messageId` | number | ID of the created message |\n\n## Response example\n\n```json\n{\n  \"success\": true,\n  \"data\": {\n    \"messageId\": 52601\n  }\n}\n```\n\n## Error response example\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"INVALID_PARAMS\",\n    \"message\": \"`uploadIds` must be an array of 1 to 10 positive integers.\"\n  }\n}\n```\n\n## Errors\n\n| HTTP | Code | Description |\n|------|-----|---------|\n| 400 | `MESSAGE_TOO_LONG` | More than 20000 Unicode code points in the outgoing text. `error.details` contains only `field: \"message\"`, `used`, `limit: 20000`, `unit: \"unicode-code-points\"`. No Bitrix24 call is made |\n| 400 | `INVALID_PARAMS` | `uploadIds` is not an array of 1–10 positive integers; `message`, `replyId`, `asFile` or `templateId` has the wrong type; `copilot` is not an object; or another body field or a query parameter was sent |\n| 400 | `INVALID_CHAT_ID` | `chatId` in the path is not a positive integer |\n| 401 | `TOKEN_MISSING` | No Bitrix24 access tokens |\n| 403 | `SCOPE_DENIED` | The API key does not have the `im` scope |\n| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only |\n| 403 | `BITRIX_ACCESS_DENIED` | No access to the chat or file in Bitrix24 |\n| 404 | `ENTITY_NOT_FOUND` | Chat or file not found |\n| 422 | `BITRIX_ERROR` | Other Bitrix24 refusal |\n| 429 | `QUEUE_TIMEOUT` | Bitrix24 request queue is busy |\n\nFull list of common API errors — [Errors](\u002Fdocs\u002Ferrors).\n\n## Known specifics\n\n**The platform does not retry the call.** After an unknown outcome, check your own state before another call so you do not create a second message.\n\n**The Bitrix24 code is not always present.** A named Bitrix24 refusal can arrive as `400`, `403`, or `404`. The `error.b24Code` field is not guaranteed in such a response.\n\n## See also\n\n- [Upload to folder](\u002Fdocs\u002Fchats\u002Ffiles\u002Fupload-to-folder)\n- [Check existence](\u002Fdocs\u002Fchats\u002Ffiles\u002Fupload-status)\n- [Discard file](\u002Fdocs\u002Fchats\u002Ffiles\u002Fupload-discard)\n- [Chat files](\u002Fdocs\u002Fchats\u002Ffiles)\n","2026-11-17",{},1795000504835]