Skip to content

Latest commit

 

History

History
315 lines (258 loc) · 8.83 KB

File metadata and controls

315 lines (258 loc) · 8.83 KB

Get Information About Attached File disk.attachedObject.get

{% note tip "" %}

If you are developing integrations for Bitrix24 using AI tools (Codex, Claude Code, Cursor), connect to the MCP server so that the assistant can utilize the official REST documentation.

{% endnote %}

Scope: disk

Who can execute the method: a user with "Read" access permission for the required file

The method disk.attachedObject.get returns information about the attached file.

Method Parameters

{% include Note on required parameters %}

#| || Name type | Description || || id* integer | Identifier of the file attachment record, which is the link connecting the disk file with other objects.

To obtain the connection identifier, use methods that return attached files. For example, if the file is attached to a task, you can find out the connection identifier using the tasks.task.get method. || |#

Code Examples

{% include Footnote on examples %}

{% list tabs %}

  • cURL (Webhook)

    curl -X POST \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -d '{"id":495}' \
    https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/disk.attachedObject.get
  • cURL (OAuth)

    curl -X POST \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -d '{"id":495,"auth":"**put_access_token_here**"}' \
    https://**put_your_bitrix24_address**/rest/disk.attachedObject.get
  • JS (TS)

    // This snippet is an ES module: top-level await requires type="module" or a bundler.
    // $b24 is an already-initialized SDK instance (see the SDK "Get started" guide).
    import { Text } from '@bitrix24/b24jssdk'
    import type { B24Frame, ISODate } from '@bitrix24/b24jssdk'
    
    declare const $b24: B24Frame
    
    // Shape of the payload returned in result (match the "response handling" section of the page)
    type AttachedObjectResult = {
      ID: string
      OBJECT_ID: string
      MODULE_ID: string
      ENTITY_TYPE: string
      ENTITY_ID: string
      CREATE_TIME: ISODate | null
      CREATED_BY: string
      DOWNLOAD_URL: string
      NAME: string
      SIZE: string
    }
    
    try {
      const response = await $b24.actions.v2.call.make<AttachedObjectResult>({
        method: 'disk.attachedObject.get',
        params: {
          id: 495,
        },
        requestId: Text.getUuidRfc4122()
      })
    
      // The payload is available only on a successful response
      if (!response.isSuccess) {
        console.error(response.getErrorMessages().join('; '))
      } else {
        const result = response.getData()!.result
        console.info('Attached file:', result.NAME, 'size:', result.SIZE, 'entity:', result.ENTITY_TYPE)
      }
    } catch (error) {
      // Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
      console.error(error)
    }
  • JS (UMD)

    <!-- Load the SDK (UMD build); it is exposed as the global B24Js -->
    <script src="https://unpkg.com/@bitrix24/b24jssdk@1/dist/umd/index.min.js"></script>
    <script>
      async function getAttachedObject() {
        try {
          // Initialize the SDK inside a Bitrix24 frame
          const $b24 = await B24Js.initializeB24Frame()
    
          const response = await $b24.actions.v2.call.make({
            method: 'disk.attachedObject.get',
            params: {
              id: 495,
            },
            requestId: B24Js.Text.getUuidRfc4122()
          })
    
          // The payload is available only on a successful response
          if (!response.isSuccess) {
            console.error(response.getErrorMessages().join('; '))
            return
          }
    
          const result = response.getData().result
          console.info('Attached file:', result.NAME, 'size:', result.SIZE, 'entity:', result.ENTITY_TYPE)
        } catch (error) {
          // Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
          console.error(error)
        }
      }
    
      document.addEventListener('DOMContentLoaded', getAttachedObject)
    </script>
  • PHP

    try {
        $response = $b24Service
            ->core
            ->call(
                'disk.attachedObject.get',
                [
                    'id' => 495
                ]
            );
    
        $result = $response
            ->getResponseData()
            ->getResult();
    
        echo 'Success: ' . print_r($result, true);
        processData($result);
    
    } catch (Throwable $e) {
        error_log($e->getMessage());
        echo 'Error retrieving attached object: ' . $e->getMessage();
    }
  • BX24.js

    BX24.callMethod(
        'disk.attachedObject.get',
        {
            id: 495
        },
        function (result) {
            if (result.error()) {
                console.error(result.error());
            } else {
                console.log(result.data());
            }
        }
    );
  • PHP CRest

    require_once('crest.php');
    
    $result = CRest::call(
        'disk.attachedObject.get',
        [
            'id' => 495
        ]
    );
    
    echo '<PRE>';
    print_r($result);
    echo '</PRE>';
  • Go

    // client and ctx are already created — see the Go SDK section
    res, err := client.Core().Call(ctx, "disk.attachedObject.get", b24.Params{
    	"id": 495,
    }, b24.WithIdempotent())
    if err != nil {
    	return fmt.Errorf("disk.attachedObject.get: %w", err)
    }
    
    var item struct {
    	ID         b24.ID `json:"ID"`
    	ObjectID   b24.ID `json:"OBJECT_ID"`
    	ModuleID   string `json:"MODULE_ID"`
    	EntityType string `json:"ENTITY_TYPE"`
    	EntityID   b24.ID `json:"ENTITY_ID"`
    	CreateTime string `json:"CREATE_TIME"`
    }
    if err := json.Unmarshal(res.Result, &item); err != nil {
    	return fmt.Errorf("parse response: %w", err)
    }
    fmt.Println(item.ID, item.ObjectID)

{% endlist %}

Response Handling

HTTP Status: 200

{
    "result": {
        "ID": "495",
        "OBJECT_ID": "8903",
        "MODULE_ID": "tasks",
        "ENTITY_TYPE": "tasks_task",
        "ENTITY_ID": "3845",
        "CREATE_TIME": "2025-12-23T10:31:24+02:00",
        "CREATED_BY": "1269",
        "DOWNLOAD_URL": "https://test.bitrix24.com/bitrix/tools/disk/uf.php?attachedId=495&auth[auth]=d78a4a690000071b006e2cf2000004f5000007746b9ad166e1b9bd67b8848714afc5a7&action=download&ncc=1",
        "NAME": "Picture.png",
        "SIZE": "52486"
    },
    "time": {
        "start": 1766489404,
        "finish": 1766489404.720053,
        "duration": 0.72005295753479,
        "processing": 0,
        "date_start": "2025-12-23T11:30:04+02:00",
        "date_finish": "2025-12-23T11:30:04+02:00",
        "operating_reset_at": 1766490004,
        "operating": 0
    }
}

Returned Data

#| || Name type | Description || || result object | Object containing data about the attached file || || ID integer | Identifier of the file attachment record || || OBJECT_ID integer | Identifier of the file || || MODULE_ID string | Module where the file is used || || ENTITY_TYPE string | Type of the linked object || || ENTITY_ID integer | Identifier of the item to which the file is attached || || CREATE_TIME string | Time of the attachment creation || || CREATED_BY integer | Identifier of the user who attached the file || || DOWNLOAD_URL string | Link to download the file || || NAME string | Name of the file || || SIZE integer | Size of the file in bytes || || time time | Information about the request execution time || |#

Error Handling

HTTP Status: 400

{
    "error":"ERROR_NOT_FOUND",
    "error_description":"Could not find entity with id `X`"
}

{% include notitle error handling %}

Possible Error Codes

#| || Code | Description | Value || || ERROR_NOT_FOUND | Could not find entity with id X | Attached file with the specified id not found || || ACCESS_DENIED | Access denied | Insufficient rights to read the attached file || |#

{% include system errors %}

Continue Learning