Add File to Chat im.disk.file.commit

Scope: im

Who 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_ID or DIALOG_ID
  • one of the file identifier parameters — FILE_ID or UPLOAD_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:

Method Parameters

Required parameters are marked with *

Name
type

Description

CHAT_ID*
integer

Identifier of the chat.

Required if DIALOG_ID is not provided

DIALOG_ID*
string

Identifier of the dialog in the format:

  • chatXXX — chat
  • sgXXX — group or project chat
  • XXX — user identifier for personal chat

Required if CHAT_ID is not provided

FILE_ID*
integer

Identifier of the file on Drive. An array can be passed.

Required if UPLOAD_ID is not provided

UPLOAD_ID*
integer

Identifier of the file on Drive. An array can be passed.

Supports an additional parameter AS_FILE, which allows sending the image without compression, as a file.

Required if FILE_ID is not provided

MESSAGE
string

Text message with the file

SILENT_MODE
string

Parameter for Open Channels chat

Possible values:

  • Y — send notification to the client
  • N — do not send notification to the client

AS_FILE
string

Send as a file. Only for UPLOAD_ID.

Possible values:

  • Y — yes
  • N — no

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
type

Description

result
object

Root object of the result (detailed description)

time
time

Information about the execution time of the request

Object result-item

Name
type

Description

FILES
object

Data of added files (detailed description)

DISK_ID
array

Array of file identifiers on Drive

FILE_MODELS
object

Models of added files on Drive (detailed description)

MESSAGE_ID
integer

Identifier of the message with files

Object FILES

Name
type

Description

upload{id}
object

File object, where id — identifier of the upload file (detailed description)

Object FILES.upload

Name
type

Description

id
integer

Identifier of the file on Drive

chatId
integer

Identifier of the chat

date
object

Date of file creation

type
string

Type of the item

name
string

Name of the file

extension
string

File extension

size
integer

Size of the file in bytes

image
object

Image parameters (detailed description)

status
string

Status of file processing

progress
integer

Progress of file processing in percentage

authorId
integer

Identifier of the file author

authorName
string

Name of the file author

urlPreview
string

Link to the file preview

urlShow
string

Link to view the file

urlDownload
string

Link to download the file

viewerAttrs
object

File viewer parameters (detailed description)

mediaUrl
object

Links to media file (detailed description)

isTranscribable
boolean

Is the file transcribable

isVideoNote
boolean

Is the file a video note

isVoiceNote
boolean

Is the file a voice note

Object image

Name
type

Description

height
integer

Height of the image

width
integer

Width of the image

Object viewerAttrs

Name
type

Description

viewer
string

Viewer identifier

viewerType
string

Type of viewer

src
string

Source file for the viewer

viewerResized
string

Source of the reduced version of the file

objectId
string

Identifier of the object in the viewer

viewerGroupBy
string

Identifier of the viewer group

imChatId
integer

Identifier of the chat for the viewer

title
string

Title in the viewer

actions
string

List of actions in the viewer in JSON string format

Object mediaUrl

Name
type

Description

preview
object

Set of links to file previews by size (detailed description)

Object mediaUrl.preview

Name
type

Description

250
string

Link to preview with a width of 250 px

Object FILE_MODELS

Name
type

Description

upload{id}
object

File model object, where id — identifier of the upload file (detailed description)

Object FILE_MODELS.upload

Name
type

Description

id
integer

Identifier of the file on Drive

name
string

Name of the file

createTime
object

Date of file creation

updateTime
object

Date of file update

deleteTime
string

Date of file deletion, can be null

code
string

File type code

xmlId
string

External identifier, can be null

storageId
integer

Identifier of the storage

realObjectId
integer

Identifier of the real object

parentId
integer

Identifier of the parent folder

deletedType
integer

Deletion type

createdBy
string

Identifier of the creator

updatedBy
string

Identifier of the updater

deletedBy
string

Identifier of the deleter

uniqueCode
string

Unique code of the file

typeFile
integer

Numeric code of the file type

globalContentVersion
integer

Global content version

fileId
integer

Identifier of the related file

size
integer

Size of the file in bytes

etag
string

ETag of the file

links
object

Links for working with the file (detailed description)

Name
type

Description

download
string

Link to download the file

showInGrid
string

Link to show the file in the grid

preview
string

Link to preview the file

Error Handling

HTTP Status: 400

{
            "error": "CHAT_ID_EMPTY",
            "error_description": "Chat ID can't be empty"
        }
        

Name
type

Description

error
string

String error code. It may consist of digits, Latin letters, and underscores

error_description
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

400

CHAT_ID_EMPTY

Chat ID can't be empty

Possible reasons:

  • one of the required parameters CHAT_ID or DIALOG_ID is not provided
  • empty CHAT_ID is passed

400

DIALOG_ID_EMPTY

Dialog ID can't be empty

Empty or invalid DIALOG_ID is passed

400

FILES_ERROR

List of files is not specified

One of the required parameters FILE_ID or UPLOAD_ID is not provided

400

SAVE_ERROR

Error during saving file to chat

Possible reasons:

  • FILE_ID or UPLOAD_ID is passed empty
  • non-existent file identifiers are passed

403

ACCESS_ERROR

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
Error Message

Description

500

INTERNAL_SERVER_ERROR
Internal server error

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

500

ERROR_UNEXPECTED_ANSWER
Server returned an unexpected response

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

503

QUERY_LIMIT_EXCEEDED
Too many requests

The request intensity limit has been exceeded

405

ERROR_BATCH_METHOD_NOT_ALLOWED
Method is not allowed for batch usage

The current method is not allowed to be called using batch

400

ERROR_BATCH_LENGTH_EXCEEDED
Max batch length exceeded

The maximum length of parameters passed to the batch method has been exceeded

401

NO_AUTH_FOUND
Wrong authorization data

Invalid access token or webhook code

400

INVALID_REQUEST
Https required

The methods must be called using the HTTPS protocol

503

OVERLOAD_LIMIT
REST API is blocked due to overload

The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support

403

ACCESS_DENIED
REST API is available only on commercial plans

The REST API is available only on commercial plans

403

INVALID_CREDENTIALS
Invalid request credentials

The user whose access token or webhook was used to call the method lacks permissions

404

ERROR_MANIFEST_IS_NOT_AVAILABLE
Manifest is not available

The manifest is not available

403

insufficient_scope
The request requires higher privileges than provided by the webhook token

The request requires higher privileges than those provided by the webhook token

401

expired_token
The access token provided has expired

The provided access token has expired

403

user_access_error
The user does not have access to the application

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

500

PORTAL_DELETED
Portal was deleted

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