For AI agents: markdown of this page — /docs-content-en/chats/files/upload-publish.md documentation index — /llms.txt

Publish uploaded files

POST /v1/chats/:chatId/files/uploads/publish

Creates 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.

Parameters

Parameter Type Required Description
ParameterchatId (path) Typenumber Requiredyes DescriptionChat ID

Request fields (body)

Field Type Required Description
FielduploadIds Typenumber[] Requiredyes Description1 to 10 positive uploaded file IDs. Get them: data.file.id in the response of Upload a file to a chat folder
Fieldmessage Typestring Requiredno DescriptionCaption
FieldreplyId Typenumber Requiredno DescriptionMessage ID to reply to
FieldasFile Typeboolean Requiredno DescriptionSend as a file
FieldtemplateId Typestring Requiredno DescriptionTemplate ID

Requires the im scope and a write-enabled key. Other fields and query parameters are rejected with 400 INVALID_PARAMS.

The 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.

If the caption exceeds the length limit, uploadIds remain available for publication with a corrected caption.

Examples

curl — personal key

Terminal
curl -X POST https://vibecode.bitrix24.com/v1/chats/42/files/uploads/publish \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"uploadIds":[7701],"message":"Caption"}'

curl — OAuth application

Terminal
curl -X POST https://vibecode.bitrix24.com/v1/chats/42/files/uploads/publish \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"uploadIds":[7701],"message":"Caption"}'

JavaScript — personal key

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/42/files/uploads/publish', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"uploadIds": [7701], "message": "Caption"}),
})
const { success, data, error } = await res.json()
console.log(success ? data : error)

JavaScript — OAuth application

javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/chats/42/files/uploads/publish', {
  method: 'POST',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({"uploadIds": [7701], "message": "Caption"}),
})
const { success, data, error } = await res.json()
console.log(success ? data : error)

Response fields

Field Type Description
Fieldsuccess Typeboolean Descriptiontrue on success
Fielddata.messageId Typenumber DescriptionID of the created message

Response example

JSON
{
  "success": true,
  "data": {
    "messageId": 52601
  }
}

Error response example

JSON
{
  "success": false,
  "error": {
    "code": "INVALID_PARAMS",
    "message": "`uploadIds` must be an array of 1 to 10 positive integers."
  }
}

Errors

HTTP Code Description
HTTP400 CodeMESSAGE_TOO_LONG DescriptionMore 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
HTTP400 CodeINVALID_PARAMS DescriptionuploadIds is not an array of 1–10 positive integers; message, replyId, asFile, or templateId has the wrong type; or another body field or a query parameter was sent
HTTP400 CodeINVALID_CHAT_ID DescriptionchatId in the path is not a positive integer
HTTP401 CodeTOKEN_MISSING DescriptionNo Bitrix24 access tokens
HTTP403 CodeSCOPE_DENIED DescriptionThe API key does not have the im scope
HTTP403 CodeWRITE_BLOCKED_READONLY_KEY DescriptionThe key is read-only
HTTP403 CodeBITRIX_ACCESS_DENIED DescriptionNo access to the chat or file in Bitrix24
HTTP404 CodeENTITY_NOT_FOUND DescriptionChat or file not found
HTTP422 CodeBITRIX_ERROR DescriptionOther Bitrix24 refusal
HTTP429 CodeQUEUE_TIMEOUT DescriptionBitrix24 request queue is busy

Full list of common API errors — Errors.

Known specifics

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.

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.

See also