Download Product Files catalog.product.download

Choose a tool for developing with an AI agent:

  • use Alaio Vibecode to build an app for Bitrix24 from a task description without knowing any programming language. The agent writes the code and deploys the app to a server, with no manual hosting setup
  • use the MCP server to develop a REST API integration in your own project. The agent refers to the official REST documentation

Scope: catalog

Who can execute the method: a user with the "View product catalog", "View catalog products", or "Edit selling price" permission and permission to read the product in the information block

The catalog.product.download method downloads product files from the trade catalog using the provided parameters.

Method Parameters

Required parameters are marked with *

Name
type

Description

fields*
object

Parameters of the file to download. Field description

Parameter fields

Name
type

Description

fileId*
integer

Identifier of the file.

The identifier is returned by the catalog.product.get and catalog.product.list methods in the detailPicture and previewPicture fields or in the value of a "File" type property

productId*
catalog_product.id

Identifier of the product.

You can retrieve product identifiers using the catalog.product.list method

fieldName*
string

Product field where the file is stored:

  • detailPicture — detailed image
  • previewPicture — preview image
  • propertyN — a "File" type property, where N is the property identifier. Instead of the identifier, you can specify the symbolic code of the property in camelCase, for example propertyMorePhoto for the MORE_PHOTO code

In catalog.product.get and catalog.product.list responses, the fieldName value is already included in the file's url and urlMachine. Pass it in the same form. The method does not accept uppercase names, such as DETAIL_PICTURE or PROPERTY_N.

You can retrieve property identifiers using the catalog.productProperty.list method

Code Examples

The examples use direct HTTP requests to save the binary response.

How to Use Examples in Documentation

curl --fail -X POST \
        -H "Content-Type: application/json" \
        -d '{"fields":{"fileId":6439,"productId":1243,"fieldName":"detailPicture"}}' \
        -o product-picture.png \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/catalog.product.download
        
curl --fail -X POST \
        -H "Content-Type: application/json" \
        -d '{"fields":{"fileId":6439,"productId":1243,"fieldName":"detailPicture"},"auth":"**put_access_token_here**"}' \
        -o product-picture.png \
        https://**put_your_bitrix24_address**/rest/catalog.product.download
        
// 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 type { B24Frame } from '@bitrix24/b24jssdk'
        
        declare const $b24: B24Frame
        
        try {
          const auth = $b24.auth.getAuthData()
          if (!auth) {
            throw new Error('No auth data')
          }
        
          // The method returns a binary file, so the request is sent directly
          const response = await fetch(`${$b24.getTargetOriginWithPath()}/catalog.product.download`, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
              fields: {
                fileId: 6439,
                productId: 1243,
                fieldName: 'detailPicture',
              },
              auth: auth.access_token,
            }),
          })
        
          if (!response.ok) {
            const error = await response.json()
            throw new Error(error.error_description)
          }
        
          const blob: Blob = await response.blob()
          console.info('File size:', blob.size, 'type:', blob.type)
        } catch (error) {
          console.error(error)
        }
        
<!-- 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 downloadProductFile() {
            try {
              // Initialize the SDK inside a Bitrix24 frame
              const $b24 = await B24Js.initializeB24Frame()
              const auth = $b24.auth.getAuthData()
              if (!auth) {
                throw new Error('No auth data')
              }
        
              // The method returns a binary file, so the request is sent directly
              const response = await fetch(`${$b24.getTargetOriginWithPath()}/catalog.product.download`, {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify({
                  fields: {
                    fileId: 6439,
                    productId: 1243,
                    fieldName: 'detailPicture',
                  },
                  auth: auth.access_token,
                }),
              })
        
              if (!response.ok) {
                const error = await response.json()
                throw new Error(error.error_description)
              }
        
              // Save the file in the browser
              const blob = await response.blob()
              const link = document.createElement('a')
              link.href = URL.createObjectURL(blob)
              link.download = 'product-picture.png'
              link.click()
              URL.revokeObjectURL(link.href)
            } catch (error) {
              console.error(error)
            }
          }
        
          document.addEventListener('DOMContentLoaded', downloadProductFile)
        </script>
        
import json
        from urllib.error import HTTPError
        from urllib.request import Request, urlopen
        
        url = "https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/catalog.product.download"
        payload = {
            "fields": {
                "fileId": 6439,
                "productId": 1243,
                "fieldName": "detailPicture",
            }
        }
        request = Request(
            url,
            data=json.dumps(payload).encode("utf-8"),
            headers={"Content-Type": "application/json"},
            method="POST",
        )
        
        try:
            with urlopen(request) as response, open("product-picture.png", "wb") as output:
                output.write(response.read())
        except HTTPError as error:
            print("Bitrix API error:", json.loads(error.read()).get("error_description"))
        
<?php
        $url = 'https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/catalog.product.download';
        $payload = json_encode([
            'fields' => [
                'fileId' => 6439,
                'productId' => 1243,
                'fieldName' => 'detailPicture',
            ],
        ], JSON_THROW_ON_ERROR);
        
        $request = curl_init($url);
        curl_setopt_array($request, [
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $payload,
            CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
            CURLOPT_RETURNTRANSFER => true,
        ]);
        
        $file = curl_exec($request);
        $status = curl_getinfo($request, CURLINFO_HTTP_CODE);
        $error = curl_error($request);
        curl_close($request);
        if ($file === false || $status !== 200) {
            throw new RuntimeException('Failed to download product file: HTTP ' . $status . ' ' . $error);
        }
        file_put_contents('product-picture.png', $file);
        
// The method returns a binary file, so the request is sent directly
        const auth = BX24.getAuth();
        
        fetch(`https://${auth.domain}/rest/catalog.product.download`, {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({
                fields: {
                    fileId: 6439,
                    productId: 1243,
                    fieldName: 'detailPicture'
                },
                auth: auth.access_token
            })
        })
            .then(response => response.ok
                ? response.blob()
                : response.json().then(error => { throw new Error(error.error_description); }))
            .then(blob => {
                const link = document.createElement('a');
                link.href = URL.createObjectURL(blob);
                link.download = 'product-picture.png';
                link.click();
                URL.revokeObjectURL(link.href);
            })
            .catch(error => console.error(error));
        
require_once('crest.php');
        
        // CRest::call() decodes the response as JSON, so the binary file is requested directly.
        // C_REST_WEB_HOOK_URL is set in settings.php
        $request = curl_init(C_REST_WEB_HOOK_URL . 'catalog.product.download');
        curl_setopt_array($request, [
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => http_build_query([
                'fields' => [
                    'fileId' => 6439,
                    'productId' => 1243,
                    'fieldName' => 'detailPicture',
                ],
            ]),
            CURLOPT_RETURNTRANSFER => true,
        ]);
        
        $file = curl_exec($request);
        $status = curl_getinfo($request, CURLINFO_HTTP_CODE);
        curl_close($request);
        
        if ($status === 200) {
            file_put_contents('product-picture.png', $file);
        } else {
            echo '<PRE>';
            print_r(json_decode($file, true));
            echo '</PRE>';
        }
        
// The method returns a binary file, so the request is sent directly
        url := "https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/catalog.product.download"
        body, err := json.Marshal(map[string]any{
        	"fields": map[string]any{
        		"fileId":    6439,
        		"productId": 1243,
        		"fieldName": "detailPicture",
        	},
        })
        if err != nil {
        	return err
        }
        
        resp, err := http.Post(url, "application/json", bytes.NewReader(body))
        if err != nil {
        	return fmt.Errorf("catalog.product.download: %w", err)
        }
        defer resp.Body.Close()
        
        if resp.StatusCode != http.StatusOK {
        	var apiErr struct {
        		Error            string `json:"error"`
        		ErrorDescription string `json:"error_description"`
        	}
        	_ = json.NewDecoder(resp.Body).Decode(&apiErr)
        	return fmt.Errorf("catalog.product.download: %s", apiErr.ErrorDescription)
        }
        
        file, err := os.Create("product-picture.png")
        if err != nil {
        	return err
        }
        defer file.Close()
        if _, err := io.Copy(file, resp.Body); err != nil {
        	return fmt.Errorf("save file: %w", err)
        }
        

Response Handling

HTTP status: 200

The response contains the file content with the Content-Type and Content-Disposition headers, for example Content-Type: image/png and Content-Disposition: attachment; filename="logo.png". The method checks that fileId belongs to the specified product and fieldName. Save the response as a file: a successful call has no JSON result field.

Returned Data

The file content is returned, not a JSON result object. Retrieve the file ID and URL from detailPicture, previewPicture, or a file property in the catalog.product.get response.

Error Handling

HTTP status: 400

{
            "error": "0",
            "error_description": "Product file wrong"
        }
        

Name
type

Description

error
string

String error code. It consists of digits, Latin letters, and underscores. It may arrive empty — in that case only error_description shows the reason

error_description
string

Error message for the developer. Do not show it to the end user without processing

Possible Error Codes

Status

Code

Description

Cause

400

200040300010

Access Denied

The user has none of the "View product catalog", "View catalog products", or "Edit selling price" permissions

400

200040300000

Iblock Not Found

The product's information block was not found

400

200040300040

Access Denied

No permission to read the product in the information block

400

Empty value

product does not exist.

No product exists with the specified productId

400

100

Could not find value for parameter {fields}

The fields parameter was not provided

400

0

Required fields: fieldName, fileId, productId

Required fields were not provided. The description lists only the missing fields

400

0

Name file field is not available

fieldName is not a "File" type field or property, or it was passed in uppercase

400

0

Product file wrong

fileId does not belong to the specified product and field

400

0

Product is empty

The file record was not found

Statuses and System Error Codes

HTTP Status: 4xx, 5xx

The errors described below are returned by the REST API itself, not by the logic of a specific method. They can arrive in response to any method.

Status

Code
Error Message

Description

500

INTERNAL_SERVER_ERROR
Internal server error

An internal server error has occurred. Retry the call, and if the error persists, contact the server administrator or Bitrix24 technical support

500

ERROR_UNEXPECTED_ANSWER
Server returned an unexpected response

The server returned an unexpected response. Retry the call, and if the error persists, contact the server administrator or Bitrix24 technical support

503

QUERY_LIMIT_EXCEEDED
Too many requests

The request intensity limit has been exceeded

429

OPERATION_TIME_LIMIT
Method is blocked due to operation time limit

The method is blocked because the request resource intensity limit has been exceeded. The block is lifted automatically once the accumulated execution time of the method no longer exceeds the limit

401

NO_AUTH_FOUND
Wrong authorization data

The request contains no authorization data: neither an access token nor a webhook code was passed

401

INVALID_REQUEST
Https required

Methods are called over the HTTPS protocol only

401

OVERLOAD_LIMIT
REST API is blocked due to overload

The REST API is blocked due to overload. This is a manual individual block. To have it lifted, contact Bitrix24 technical support

401

ACCESS_DENIED
REST is available only on commercial plans

REST API access is not active for this account. In Bitrix24 Cloud, check the current plan or trial status: Vibe+ plans include REST API access, while Essentials plans do not. A webhook receives a different error message — REST is available only by subscription

401

INVALID_CREDENTIALS
Invalid request credentials

No active webhook with the specified user identifier and secret code was found

404

ERROR_METHOD_NOT_FOUND
Method not found!

No method with this name was found. The name is misspelled, the method does not exist in the REST API, or it is unavailable without the required scope

401

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

The request requires broader permissions than the token has: for a webhook these are the permissions granted to it, for an application it is the scope. For an application, the error message ends with provided by the access token

401

expired_token
The access token provided has expired

The access token has expired

401

user_access_error
The user does not have access to the application

The application is installed, but the Bitrix24 administrator has granted access to it only to specific users

403

PORTAL_DELETED
Portal was deleted

The public part of the site is closed. To open it on an on-premise installation, disable the "Temporary closure of the public part of the site" option. Path to the setting: Desktop > Settings > Product Settings > Module Settings > Main Module > Temporary closure of the public part of the site

Continue Learning