How to Execute a Batch Request

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: basic

Who can execute the method: any user

The batch method executes several Bitrix24 REST API requests in a single server call — either independent or linked, where the result of one request is passed to the next.

When to Use Batch

The method is suitable for two tasks:

  • multiple independent calls in a single request — when you need to execute a group of methods whose results do not depend on each other. Using one batch instead of several separate calls reduces the number of requests to the server.
  • linked calls with data passing — when the result of one method must be passed into the parameters of the next. Requests are executed sequentially, so data from a previous call is available in subsequent calls.

Consider the following limitations:

  • A single batch contains no more than 50 subqueries.
  • Nesting is prohibited: you cannot call another batch inside batch.

Method Parameters

Required parameters are marked with *

Name
type

Description

cmd*
array

An array of subqueries. The item key is the subquery identifier, and the value is the called method with parameters as a string method?parameter=value. In the SDK, item can be specified as an object with fields method and params

halt
boolean

Determines whether to interrupt the sequence of requests in case of an error. Accepts boolean values true and false or their numerical equivalents 1 and 0. Defaults to false

Subquery data is encoded differently depending on how the batch is transmitted. In a POST request body in JSON format, as in the examples below, values cmd are passed as plain strings without additional encoding. If the batch is passed via URL query parameters, the subquery data is URL-encoded, and since the entire batch itself becomes a parameter value, it undergoes double encoding.

Note

The number of requests in a batch is limited to 50. If this limit is exceeded, subqueries beyond the limit will end with an error ERROR_BATCH_LENGTH_EXCEEDED.

The array of requests can use numeric keys or be associative. In the parameters of each subsequent request, you can use data from previous requests in the following manner:


        $result[request_id][response_field]
        
        

where the request identifier is its key in the request array.

As of version rest 24.0.0, nesting is prohibited for the batch method: when calling the batch method, you cannot call another batch inside it. Such a subquery ends with an error ERROR_BATCH_METHOD_NOT_ALLOWED.

Code Examples

How to Use Examples in Documentation

Independent Calls

A batch consisting of several different methods whose results do not depend on each other. Each subquery is executed separately, and no data is passed between them.

curl -X POST \
        -H "Content-Type: application/json" \
        -d '{
                "halt": 0,
                "cmd": {
                    "get_user": "user.current",
                    "get_departments": "department.get",
                    "get_app": "app.info"
                }
            }' \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/batch
        
curl -X POST \
        -H "Content-Type: application/json" \
        -d '{
                "halt": 0,
                "cmd": {
                    "get_user": "user.current",
                    "get_departments": "department.get",
                    "get_app": "app.info"
                },
                "auth":"**put_access_token_here**"
            }' \
        https://**put_your_bitrix24_address**/rest/batch
        
// 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 } from '@bitrix24/b24jssdk'
        
        declare const $b24: B24Frame
        
        try {
          // Named commands: each key becomes the identifier of its subrequest
          const response = await $b24.actions.v2.batch.make({
            calls: {
              get_user: { method: 'user.current', params: {} },
              get_departments: { method: 'department.get', params: {} },
              get_app: { method: 'app.info', params: {} }
            },
            options: {
              isHaltOnError: false, // analog of halt = 0: run every subrequest
              returnAjaxResult: true, // wrap each subrequest result in an AjaxResult
              requestId: Text.getUuidRfc4122()
            }
          })
        
          // isSuccess reflects the batch call as a whole
          if (!response.isSuccess) {
            console.error(response.getErrorMessages().join('; '))
          } else {
            // getData() returns an object keyed by the command names above
            const result = response.getData()
            console.info(result.get_user.getData()?.result)
            console.info(result.get_departments.getData()?.result)
            console.info(result.get_app.getData()?.result)
          }
        } catch (error) {
          // Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
          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 runBatch() {
            try {
              // Initialize the SDK inside a Bitrix24 frame
              const $b24 = await B24Js.initializeB24Frame()
        
              // Named commands: each key becomes the identifier of its subrequest
              const response = await $b24.actions.v2.batch.make({
                calls: {
                  get_user: { method: 'user.current', params: {} },
                  get_departments: { method: 'department.get', params: {} },
                  get_app: { method: 'app.info', params: {} }
                },
                options: {
                  isHaltOnError: false, // analog of halt = 0: run every subrequest
                  returnAjaxResult: true, // wrap each subrequest result in an AjaxResult
                  requestId: B24Js.Text.getUuidRfc4122()
                }
              })
        
              // isSuccess reflects the batch call as a whole
              if (!response.isSuccess) {
                console.error(response.getErrorMessages().join('; '))
                return
              }
        
              // getData() returns an object keyed by the command names above
              const result = response.getData()
              console.info(result.get_user.getData()?.result)
              console.info(result.get_departments.getData()?.result)
              console.info(result.get_app.getData()?.result)
            } catch (error) {
              // Thrown on transport or SDK failures (AjaxError, SdkError, etc.)
              console.error(error)
            }
          }
        
          document.addEventListener('DOMContentLoaded', runBatch)
        </script>
        
BX24.callBatch({
            get_user: ['user.current', {}],
            get_departments: ['department.get', {}],
            get_app: ['app.info', {}]
        }, function(result) {
        
            console.log('get_user result: ', result.get_user.data());
            console.log('get_departments result: ', result.get_departments.data());
            console.log('get_app result: ', result.get_app.data());
        });
        

For more details, see the callBatch method article in the BX24.JS SDK documentation.

$result = \CRest::callBatch(
            // Commands
            [
                'get_user' => [
                    'method' => 'user.current',
                    'params' => []
                ],
                'get_departments' => [
                    'method' => 'department.get',
                    'params' => []
                ],
                'get_app' => [
                    'method' => 'app.info',
                    'params' => []
                ],
            ],
            // Halt
            false
        );
        
        echo "<pre>";
        var_dump($result);
        echo "</pre>";
        

Linked Calls

Subqueries are executed sequentially, so the result of a previous request can be passed into the parameters of the next request using the $result[request_id][response_field] syntax. In the example below, the department.get method retrieves the department identifier from the result of user.current.

curl -X POST \
        -H "Content-Type: application/json" \
        -d '{
                "halt": 0,
                "cmd": {
                    "get_user": "user.current",
                    "get_department": "department.get?ID=$result[get_user][UF_DEPARTMENT][0]"
                }
            }' \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/batch
        
curl -X POST \
        -H "Content-Type: application/json" \
        -d '{
                "halt": 0,
                "cmd": {
                    "get_user": "user.current",
                    "get_department": "department.get?ID=$result[get_user][UF_DEPARTMENT][0]"
                },
                "auth":"**put_access_token_here**"
            }' \
        https://**put_your_bitrix24_address**/rest/batch
        
BX24.callBatch({
            get_user: ['user.current', {}],
            get_department: {
                method: 'department.get',
                params: {
                    ID: '$result[get_user][UF_DEPARTMENT][0]'
                }
            }
        }, function(result) {
        
            console.log('Raw result: ', result);
            console.log('get_user result: ', result.get_user.data());
            console.log('get_department result: ', result.get_department.data());
        });
        

For more details, see the callBatch method article in the BX24.JS SDK documentation.

$result = \CRest::callBatch(
            // Commands
            [
                'get_user' => [
                    'method' => 'user.current',
                    'params' => []
                ],
                'get_department' => [
                    'method' => 'department.get',
                    'params' => [
                        "ID" => '$result[get_user][UF_DEPARTMENT][0]'
                    ]
                ],
            ],
            // Halt
            false
        );
        
        echo "<pre>";
        var_dump($result);
        echo "</pre>";
        

Note

If an intermediate method is a list method, it returns an array of records; therefore, when accessing the result, specify the index of the required record. For example, in the $result[user_by_name][0][ID] syntax for the user.search method, the identifier of the first found user is retrieved.

Response Handling

HTTP status: 200

{
            "result": {
                "result": {
                    "get_user": {
                        "ID": "1",
                        "ACTIVE": true,
                        "NAME": "John",
                        "LAST_NAME": "Doe",
                        "EMAIL": "my@example.com",
                        "LAST_LOGIN": "2024-08-29T10:29:54+03:00",
                        "DATE_REGISTER": "2023-08-24T03:00:00+03:00",
                        "IS_ONLINE": "Y",
                        "TIMESTAMP_X": "24.08.2023 13:19:39",
                        "LAST_ACTIVITY_DATE": "2024-08-29 10:30:11",
                        "PERSONAL_GENDER": "",
                        "PERSONAL_BIRTHDAY": "",
                        "UF_EMPLOYMENT_DATE": "",
                        "UF_DEPARTMENT": [
                            1
                        ]
                    },
                    "get_department": [
                        {
                            "ID": "1",
                            "NAME": "DEMO",
                            "SORT": 500
                        }
                    ]
                },
                "result_error": [],
                "result_total": {
                    "get_department": 1
                },
                "result_next": [],
                "result_time": {
                    "get_user": {
                        "start": 1724916859.46156,
                        "finish": 1724916859.464775,
                        "duration": 0.0032150745391845703,
                        "processing": 0.003075838088989258,
                        "date_start": "2024-08-29T10:34:19+03:00",
                        "date_finish": "2024-08-29T10:34:19+03:00"
                    },
                    "get_department": {
                        "start": 1724916859.464944,
                        "finish": 1724916859.471518,
                        "duration": 0.006574153900146484,
                        "processing": 0.005941152572631836,
                        "date_start": "2024-08-29T10:34:19+03:00",
                        "date_finish": "2024-08-29T10:34:19+03:00"
                    }
                }
            },
            "time": {
                "start": 1724916859.421475,
                "finish": 1724916859.471588,
                "duration": 0.05011296272277832,
                "processing": 0.010200977325439453,
                "date_start": "2024-08-29T10:34:19+03:00",
                "date_finish": "2024-08-29T10:34:19+03:00"
            }
        }
        

Returned Data

Name
type

Description

result
object

The root response object containing the results of the called methods (detailed description)

time
time

Information about the total request execution time

Result Object

The keys in all object fields are the subquery identifiers from the cmd array.

Name
type

Description

result
object

Results of successfully executed subqueries. The value of each field contains the data returned by the corresponding method

result_error
object

Subquery errors. The value of each field contains error — the error code and error_description — the error description. Empty if there are no errors

result_total
object

Total number of records for list methods. The value of each field is the number of records found for the corresponding subquery

result_next
object

The value of the start parameter to retrieve the next page of results for list methods. Present only for subqueries that have a next page

result_time
time

Information about the execution time of each subquery

Error Handling

The batch method does not return a single error for the entire batch — the request itself completes with a 200 status. The result of each sub-request that ends in an error is placed in the result_error field under the key of that specific sub-request. Successfully executed sub-requests remain in the result field.

Error behavior depends on the halt parameter:

  • halt = 0 — all sub-requests in the batch are executed, and errors are collected in result_error for each problematic sub-request
  • halt = 1 — execution of the chain is interrupted at the first sub-request that returns an error; subsequent sub-requests are not executed
{
            "result": {
                "result": [],
                "result_error": {
                    "get_user": {
                        "error": "insufficient_scope",
                        "error_description": ""
                    },
                    "get_department": {
                        "error": "insufficient_scope",
                        "error_description": ""
                    }
                },
                "result_total": [],
                "result_next": [],
                "result_time": []
            },
            "time": {
                "start": 1724916638.077564,
                "finish": 1724916638.132399,
                "duration": 0.05483508110046387,
                "processing": 0.0017969608306884766,
                "date_start": "2024-08-29T10:30:38+03:00",
                "date_finish": "2024-08-29T10:30:38+03:00"
            }
        }
        
{
            "result": {
                "result": [],
                "result_error": {
                    "get_user": {
                        "error": "insufficient_scope",
                        "error_description": ""
                    }
                },
                "result_total": [],
                "result_next": [],
                "result_time": []
            },
            "time": {
                "start": 1724916725.460891,
                "finish": 1724916725.851307,
                "duration": 0.39041590690612793,
                "processing": 0.0005991458892822266,
                "date_start": "2024-08-29T10:32:05+03:00",
                "date_finish": "2024-08-29T10:32:05+03:00"
            }
        }
        

Each item in the result_error field contains information about the sub-request error:

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

Value

200

ERROR_BATCH_METHOD_NOT_ALLOWED

Method is not allowed for batch usage

The method cannot be called inside batch: this is a file upload or download or a nested batch

200

ERROR_BATCH_LENGTH_EXCEEDED

Max batch length exceeded

More than 50 subqueries were passed in the batch. The first 50 are executed, and every subquery beyond that returns this error

When designing a command chain, do not neglect the halt key — with a value of 1, it will interrupt the execution of the chain if one request in the chain returns an error.

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