Send a batch of requests with BX24.callBatch
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
void BX24.callBatch(
Object|Array calls,
[Function callback[,
Boolean bHaltOnError = false]]
);
The BX24.callBatch function sends several Bitrix24 method calls in a single request on behalf of the user who opened the application. A batch is useful when you need to perform a series of calls in a row: for example, to create the required objects during application installation, or to retrieve a user together with their department.
The function returns nothing: the results of all commands are passed to the callback function. If you call BX24.callBatch before BX24.init, the library defers the request until initialization completes.
The function works only inside the frame of an application and only when the BX24.js library is loaded — the Library Overview describes how to load it.
Parameters
Required parameters are marked with *
|
Name |
Description |
|
Batch commands — an array or an object of commands (detailed description). The object keys become the result keys in A batch can contain no more than 50 commands: Bitrix24 does not execute the rest. The library does not send an empty batch, and |
|
|
callback |
Function that receives the command results. Their structure is described in the Response Handling section |
|
bHaltOnError |
Whether to stop the batch at the first error. Commands after the error are not executed, and their keys are absent from the result. Default is |
Batch Command
A command can be written as an array [method, params] or as an object {method, params}.
|
Name |
Description |
|
method* |
Bitrix24 method name, for example, user.current. The library skips a command without a method name |
|
params |
Method parameters in the same format as for BX24.callMethod. If the method has no required parameters, you can omit You can refer to the result of a previous command using the |
Code Examples
How to Use Examples in Documentation
Retrieve the current user using the user.current method and, in the same batch, their departments using the department.get method. The second command takes the department IDs from the response of the first one using a macro. The UF_DEPARTMENT field is an array, and department.get also accepts a list of IDs in the ID parameter, so it returns the user's departments. Any user can call both methods. The application needs the department scope and one of the scopes for user data: user, user_brief, or user_basic:
BX24.init(() => {
BX24.callBatch({
get_user: ['user.current', {}],
get_department: {
method: 'department.get',
params: {
ID: '$result[get_user][UF_DEPARTMENT]',
},
},
}, (result) => {
for (const key of ['get_user', 'get_department'])
{
// with bHaltOnError = true, commands after an error are absent from the result
if (!result[key])
{
console.error(key + ': command was not executed');
return;
}
if (result[key].error())
{
console.error(key + ': ' + result[key].error().toString());
return;
}
}
const user = result.get_user.data();
const departments = result.get_department.data().map((department) => department.NAME);
console.log(user.NAME + ' ' + user.LAST_NAME + ': ' + departments.join(', ')); // Klaus Weber: Sales Department
}, true);
});
Response Handling
Bitrix24 returns a single response to the batch, in which the data, errors, and metadata of each command are grouped by key. The raw response to the batch from the example above, with the user data abbreviated:
{
"result": {
"result": {
"get_user": {
"ID": "10",
"ACTIVE": true,
"NAME": "Klaus",
"LAST_NAME": "Weber",
"UF_DEPARTMENT": [1]
},
"get_department": [
{
"ID": "1",
"NAME": "Sales Department",
"SORT": 500
}
]
},
"result_error": [],
"result_total": {
"get_department": 1
},
"result_next": [],
"result_time": {
"get_user": {
"start": 1790289763,
"finish": 1790289763.9619,
"duration": 0.9619,
"processing": 0,
"date_start": "2026-09-24T22:42:43+00:00",
"date_finish": "2026-09-24T22:42:43+00:00"
},
"get_department": {
"start": 1790289763,
"finish": 1790289763.9637,
"duration": 0.9637,
"processing": 0,
"date_start": "2026-09-24T22:42:43+00:00",
"date_finish": "2026-09-24T22:42:43+00:00"
}
}
},
"time": {
"start": 1790289763,
"finish": 1790289763.9651,
"duration": 0.9651,
"processing": 0,
"date_start": "2026-09-24T22:42:43+00:00",
"date_finish": "2026-09-24T22:42:43+00:00"
}
}
The library splits this response by command. If calls is an object, callback receives results with the same keys; if it is an array, callback receives an array of results in the same order. Each result is an ajaxResult object. Its methods read the fields of the raw response by the command key:
|
Method |
Raw response field |
What it returns |
|
|
|
The command data. For a command with an error, an empty object |
|
|
|
An error object, or |
|
|
|
The total number of records in the list, or |
|
|
|
|
|
|
|
Requests the next page. It returns |
For example, result.get_department.data() returns the array from the result.result.get_department field. All fields of the raw response are described on the page of the batch method.
A command result differs from a BX24.callMethod result:
error_description()always returnsundefined. The error message is inresult[key].error().ex.error_description- the
answerproperty does not contain the request execution time next()requests the next page with a separate method call, outside the batch. Pass a separate handler tonext(): without it, the page is passed to the batchcallbackas a single result rather than as an object with keys- if the command parameters contain a
$resultmacro,next()sends it as is: Bitrix24 substitutes macros only inside a batch. For such a command, request the next page with a new batch of one command, with resolved parameter values and thestartparameter. This does not work with BX24.callMethod: the library removes a non-zerostartfromparams
Error Handling
An error is returned for each command separately. If bHaltOnError is not enabled, the remaining commands of the batch are executed. The result[key].error() method returns the same error object as BX24.callMethod. The HTTP status in it is the status of the entire batch, so for a command error it is usually 200:
{
"status": 200,
"ex": {
"error": "ERROR_METHOD_NOT_FOUND",
"error_description": "Method not found!"
}
}
In the raw batch response, this error is in the result.result_error field under the command key — see the example on the page of the batch method.
If bHaltOnError is enabled, the keys of commands after the error are absent from the result. Check that the key exists before calling error(): otherwise, the handler stops with a JavaScript error.
|
Name |
Description |
|
error |
String error code. It consists of digits, Latin letters, and underscores. It may arrive empty — in that case only |
|
error_description |
Error message for the developer. Do not show it to the end user without processing |
Possible Error Codes
Command error codes depend on the called method and are described on its page. Errors of the batch itself:
|
Status |
Code |
Description |
Meaning |
|
|
|
Max batch length exceeded |
The batch contains more than 50 commands. If |
|
|
|
Method is not allowed for batch usage |
The method cannot be called inside a batch, for example, a nested batch |
The following are not passed to callback:
- the
expired_tokenerror. The library refreshes the authorization itself and retries the batch, andcallbackreceives the result of the retry - any other error that Bitrix24 returns for the entire batch rather than for an individual command. The library stops with a JavaScript error while parsing the response
- a response with a
5xxstatus, a network failure, and a response that could not be parsed as JSON. The library throws aQuery error!exception from the asynchronous request handler, so atry/catcharound the call does not catch it
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 |
Description |
|
|
|
An internal server error has occurred. Retry the call, and if the error persists, contact the server administrator or Bitrix24 technical support |
|
|
|
The server returned an unexpected response. Retry the call, and if the error persists, contact the server administrator or Bitrix24 technical support |
|
|
|
The request intensity limit has been exceeded |
|
|
|
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 |
|
|
|
The request contains no authorization data: neither an access token nor a webhook code was passed |
|
|
|
Methods are called over the HTTPS protocol only |
|
|
|
The REST API is blocked due to overload. This is a manual individual block. To have it lifted, contact Bitrix24 technical support |
|
|
|
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 — |
|
|
|
No active webhook with the specified user identifier and secret code was 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 |
|
|
|
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 |
|
|
|
The access token has expired |
|
|
|
The application is installed, but the Bitrix24 administrator has granted access to it only to specific users |
|
|
|
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 |