Add File to Chat im.disk.file.commit
Scope:
imWho can execute the method: chat participant
The method im.disk.file.commit adds a file to a chat.
To add a file, specify:
- one of the chat identifier parameters —
CHAT_IDorDIALOG_ID - one of the file identifier parameters —
FILE_IDorUPLOAD_ID
If multiple parameters are passed simultaneously, the method processes only the first one.
You can obtain the identifier of the new file after uploading it using the method disk.folder.upload.file. To get the identifier of an existing file, use:
- disk.storage.getchildren — if the file is located in the root of the storage
- disk.folder.getchildren — if the file is located in a folder
Method Parameters
Required parameters are marked with *
|
Name |
Description |
|
CHAT_ID* |
Identifier of the chat. Required if |
|
DIALOG_ID* |
Identifier of the dialog in the format:
Required if |
|
FILE_ID* |
Identifier of the file on Drive. An array can be passed. Required if |
|
UPLOAD_ID* |
Identifier of the file on Drive. An array can be passed. Supports an additional parameter Required if |
|
MESSAGE |
Text message with the file |
|
SILENT_MODE |
Parameter for Open Channels chat Possible values:
|
|
AS_FILE |
Send as a file. Only for Possible values:
|
Code Examples
How to Use Examples in Documentation
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"CHAT_ID":1489,"FILE_ID":[5249,5250],"MESSAGE":"Project documents"}' \
https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/im.disk.file.commit
curl -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{"CHAT_ID":1489,"FILE_ID":[5249,5250],"MESSAGE":"Project documents","auth":"**put_access_token_here**"}' \
https://**put_your_bitrix24_address**/rest/im.disk.file.commit
try
{
const response = await $b24.callMethod(
'im.disk.file.commit',
{
CHAT_ID: 1489,
FILE_ID: [5249, 5250],
MESSAGE: 'Project documents',
}
);
console.log(response.getData().result);
}
catch (error)
{
console.error(error);
}
try {
$response = $b24Service
->core
->call(
'im.disk.file.commit',
[
'CHAT_ID' => 1489,
'FILE_ID' => [5249, 5250],
'MESSAGE' => 'Project documents',
]
);
$result = $response
->getResponseData()
->getResult();
echo 'Success: ' . print_r($result, true);
} catch (Throwable $e) {
error_log($e->getMessage());
echo 'Error: ' . $e->getMessage();
}
BX24.callMethod(
'im.disk.file.commit',
{
CHAT_ID: 1489,
FILE_ID: [5249, 5250],
MESSAGE: 'Project documents',
},
function(result)
{
if (result.error())
{
console.error(result.error());
}
else
{
console.log(result.data());
}
}
);
require_once('crest.php');
$result = CRest::call(
'im.disk.file.commit',
[
'CHAT_ID' => 1489,
'FILE_ID' => [5249, 5250],
'MESSAGE' => 'Project documents',
]
);
echo '<PRE>';
print_r($result);
echo '</PRE>';
Response Handling
HTTP Status: 200
{
"result": {
"FILES": {
"upload5249": {
"id": 5249,
"chatId": 1489,
"date": {},
"type": "file",
"name": "image.png",
"extension": "png",
"size": 2144,
"image": {
"height": 61,
"width": 72
},
"status": "done",
"progress": 100,
"authorId": 503,
"authorName": "John Smith",
"urlPreview": "https://mysite.com/bitrix/services/main/ajax.php?action=disk.api.file.download&SITE_ID=s1&humanRE=1&fileId=5249&exact=N&_esd=hpbccd%2FZFlCVMvT8%2FoXYU%2FfMrCjiXqxIAf6V4Sv1rR0euQRiW7%2BsdhF7n1QGRL8ZBBmpuiVaX9sY2NbsyigTzBiykXGbFEbXUAmoPO8IvcdVkdoD5n6CJHZG9DZ0DRpH6i5goVbMdjo%3D&fileName=image.png",
"urlShow": "https://mysite.com/bitrix/services/main/ajax.php?action=disk.api.file.showImage&SITE_ID=s1&humanRE=1&fileId=5249&width=1280&height=1280&signature=9f56cfa3412e55679012a6c3bef9ff391f1fc7becf6dc42bea2b8d68656934ce&exact=N&_esd=hpbccd%2FZFlCVMvT8%2FoXYU%2FfMrCjiXqxIAf6V4Sv1rR0euQRiW7%2BsdhF7n1QGRL8ZBBmpuiVaX9sY2NbsyigTzBiykXGbFEbXUAmoPO8IvcdVkdoD5n6CJHZG9DZ0DRpH6i5goVbMdjo%3D&fileName=image.png",
"urlDownload": "https://mysite.com/bitrix/services/main/ajax.php?action=disk.api.file.download&SITE_ID=s1&humanRE=1&fileId=5249&exact=N&_esd=hpbccd%2FZFlCVMvT8%2FoXYU%2FfMrCjiXqxIAf6V4Sv1rR0euQRiW7%2BsdhF7n1QGRL8ZBBmpuiVaX9sY2NbsyigTzBiykXGbFEbXUAmoPO8IvcdVkdoD5n6CJHZG9DZ0DRpH6i5goVbMdjo%3D&fileName=image.png",
"viewerAttrs": {
"viewer": "",
"viewerType": "image",
"src": "https://mysite.com/bitrix/services/main/ajax.php?action=disk.api.file.download&SITE_ID=s1&humanRE=1&fileId=5249&exact=N&_esd=hpbccd%2FZFlCVMvT8%2FoXYU%2FfMrCjiXqxIAf6V4Sv1rR0euQRiW7%2BsdhF7n1QGRL8ZBBmpuiVaX9sY2NbsyigTzBiykXGbFEbXUAmoPO8IvcdVkdoD5n6CJHZG9DZ0DRpH6i5goVbMdjo%3D&fileName=image.png",
"viewerResized": "",
"objectId": "5249",
"viewerGroupBy": "1489",
"imChatId": 1489,
"title": "image.png",
"actions": "[{\"type\":\"download\"},{\"type\":\"copyToMe\",\"text\":\"Save to Drive\",\"action\":\"BXIM.disk.saveToDiskAction\",\"params\":{\"fileId\":\"5249\"},\"extension\":\"disk.viewer.actions\",\"buttonIconClass\":\"ui-btn-icon-cloud\"}]"
},
"mediaUrl": {
"preview": {
"250": "https://mysite.com/bitrix/services/main/ajax.php?action=disk.api.file.download&SITE_ID=s1&humanRE=1&fileId=5249&exact=N&_esd=hpbccd%2FZFlCVMvT8%2FoXYU%2FfMrCjiXqxIAf6V4Sv1rR0euQRiW7%2BsdhF7n1QGRL8ZBBmpuiVaX9sY2NbsyigTzBiykXGbFEbXUAmoPO8IvcdVkdoD5n6CJHZG9DZ0DRpH6i5goVbMdjo%3D&fileName=image.png"
}
},
"isTranscribable": false,
"isVideoNote": false,
"isVoiceNote": false
}
},
"DISK_ID": [
"5249"
],
"FILE_MODELS": {
"upload5249": {
"id": 5249,
"name": "image.png",
"createTime": {},
"updateTime": {},
"deleteTime": null,
"code": "media_original",
"xmlId": null,
"storageId": 663,
"realObjectId": 5249,
"parentId": 4821,
"deletedType": 0,
"createdBy": "503",
"updatedBy": "503",
"deletedBy": "0",
"uniqueCode": "k7lj3sQxTRWSi6K93Vyh",
"typeFile": 2,
"globalContentVersion": 2,
"fileId": 57077,
"size": 2144,
"etag": "73c045036a9e96943fa57316371655c2",
"links": {
"download": "/bitrix/services/main/ajax.php?action=disk.file.download&SITE_ID=s1&fileId=5249",
"showInGrid": "/bitrix/tools/disk/focus.php?objectId=5249&action=showObjectInGrid&ncc=1",
"preview": "/bitrix/services/main/ajax.php?action=disk.api.file.showImage&SITE_ID=s1&humanRE=1&width=640&height=640&signature=8e152b3f4820b07a3f8ea79a6de60b0ae5a82a57467d08d1e8a8a399afb0330f&fileId=5249"
}
}
},
"MESSAGE_ID": 84779
},
"time": {
"start": 1772451339,
"finish": 1772451339.658828,
"duration": 0.6588280200958252,
"processing": 0,
"date_start": "2026-03-02T14:35:39+01:00",
"date_finish": "2026-03-02T14:35:39+01:00",
"operating_reset_at": 1772451939,
"operating": 0
}
}
Returned Data
|
Name |
Description |
|
result |
Root object of the result (detailed description) |
|
time |
Information about the execution time of the request |
Object result-item
|
Name |
Description |
|
FILES |
Data of added files (detailed description) |
|
DISK_ID |
Array of file identifiers on Drive |
|
FILE_MODELS |
Models of added files on Drive (detailed description) |
|
MESSAGE_ID |
Identifier of the message with files |
Object FILES
|
Name |
Description |
|
upload{id} |
File object, where |
Object FILES.upload
|
Name |
Description |
|
id |
Identifier of the file on Drive |
|
chatId |
Identifier of the chat |
|
date |
Date of file creation |
|
type |
Type of the item |
|
name |
Name of the file |
|
extension |
File extension |
|
size |
Size of the file in bytes |
|
image |
Image parameters (detailed description) |
|
status |
Status of file processing |
|
progress |
Progress of file processing in percentage |
|
authorId |
Identifier of the file author |
|
authorName |
Name of the file author |
|
urlPreview |
Link to the file preview |
|
urlShow |
Link to view the file |
|
urlDownload |
Link to download the file |
|
viewerAttrs |
File viewer parameters (detailed description) |
|
mediaUrl |
Links to media file (detailed description) |
|
isTranscribable |
Is the file transcribable |
|
isVideoNote |
Is the file a video note |
|
isVoiceNote |
Is the file a voice note |
Object image
|
Name |
Description |
|
height |
Height of the image |
|
width |
Width of the image |
Object viewerAttrs
|
Name |
Description |
|
viewer |
Viewer identifier |
|
viewerType |
Type of viewer |
|
src |
Source file for the viewer |
|
viewerResized |
Source of the reduced version of the file |
|
objectId |
Identifier of the object in the viewer |
|
viewerGroupBy |
Identifier of the viewer group |
|
imChatId |
Identifier of the chat for the viewer |
|
title |
Title in the viewer |
|
actions |
List of actions in the viewer in JSON string format |
Object mediaUrl
|
Name |
Description |
|
preview |
Set of links to file previews by size (detailed description) |
Object mediaUrl.preview
|
Name |
Description |
|
250 |
Link to preview with a width of 250 px |
Object FILE_MODELS
|
Name |
Description |
|
upload{id} |
File model object, where |
Object FILE_MODELS.upload
|
Name |
Description |
|
id |
Identifier of the file on Drive |
|
name |
Name of the file |
|
createTime |
Date of file creation |
|
updateTime |
Date of file update |
|
deleteTime |
Date of file deletion, can be |
|
code |
File type code |
|
xmlId |
External identifier, can be |
|
storageId |
Identifier of the storage |
|
realObjectId |
Identifier of the real object |
|
parentId |
Identifier of the parent folder |
|
deletedType |
Deletion type |
|
createdBy |
Identifier of the creator |
|
updatedBy |
Identifier of the updater |
|
deletedBy |
Identifier of the deleter |
|
uniqueCode |
Unique code of the file |
|
typeFile |
Numeric code of the file type |
|
globalContentVersion |
Global content version |
|
fileId |
Identifier of the related file |
|
size |
Size of the file in bytes |
|
etag |
ETag of the file |
|
links |
Links for working with the file (detailed description) |
Object links
|
Name |
Description |
|
download |
Link to download the file |
|
showInGrid |
Link to show the file in the grid |
|
preview |
Link to preview the file |
Error Handling
HTTP Status: 400
{
"error": "CHAT_ID_EMPTY",
"error_description": "Chat ID can't be empty"
}
|
Name |
Description |
|
error |
String error code. It may consist of digits, Latin letters, and underscores |
|
error_description |
Textual description of the error. The description is not intended to be shown to the end user in its raw form |
Possible Error Codes
|
Status |
Code |
Description |
Value |
|
|
|
Chat ID can't be empty |
Possible reasons:
|
|
|
|
Dialog ID can't be empty |
Empty or invalid |
|
|
|
List of files is not specified |
One of the required parameters |
|
|
|
Error during saving file to chat |
Possible reasons:
|
|
|
|
You do not have access to the specified dialog |
Insufficient rights to view the dialog or a non-existent dialog is passed |
Statuses and System Error Codes
HTTP Status: 20x, 40x, 50x
The errors described below may occur when calling any method.
|
Status |
Code |
Description |
|
|
|
An internal server error has occurred, please contact the server administrator or Bitrix24 technical support |
|
|
|
An internal server error has occurred, please contact the server administrator or Bitrix24 technical support |
|
|
|
The request intensity limit has been exceeded |
|
|
|
The current method is not allowed to be called using batch |
|
|
|
The maximum length of parameters passed to the batch method has been exceeded |
|
|
|
Invalid access token or webhook code |
|
|
|
The methods must be called using the HTTPS protocol |
|
|
|
The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support |
|
|
|
The REST API is available only on commercial plans |
|
|
|
The user whose access token or webhook was used to call the method lacks permissions |
|
|
|
The manifest is not available |
|
|
|
The request requires higher privileges than those provided by the webhook token |
|
|
|
The provided access token has expired |
|
|
|
The user does not have access to the application. This means that the application is installed, but the account administrator has allowed access to this application only for specific users |
|
|
|
The public part of the site is closed. To open the public part of the site on an on-premise installation, disable the option "Temporary closure of the public part of the site". Path to the setting: Desktop > Settings > Product Settings > Module Settings > Main Module > Temporary closure of the public part of the site |
Continue Learning
- Save File to Your Drive im.disk.file.save
- Delete File from Chat Folder im.disk.file.delete
- Get Chat File Storage Folder im.disk.folder.get