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
In some cases, there is a need to send multiple requests in succession. For example, when creating necessary entities during the application installation process. To optimize the process, batch execution of requests can be used.
void BX24.callBatch(
Object|Array calls,
[Function callback[,
Boolean bHaltOnError = false]]
);
The function BX24.callBatch sends a batch of requests to the REST service. If called before BX24.init, the request execution will be delayed.
Parameters
Required parameters are marked with *
|
Name |
Description |
|
A regular or associative array (object) with requests. Each request is either an array In the method parameters, macros can be used to access the results of previous requests in the current batch. A macro can be constructed like this: |
|
|
callback |
A handler function for the batch request result. It will receive an array or associative array (object) of ajaxResult objects with keys corresponding to the keys from the request batch |
|
bHaltOnError |
Flag "halt execution of the batch in case of an error". Default is |
Example
BX24.init(() => {
const prepareMessage = (name, lastName, departmentNumber) => {
return `The current user ${name} ${lastName} is assigned to the departmen${departmentNumber > 1 ? 'ts ' : 't '}`;
};
BX24.callBatch({
get_user: ['user.current', {}],
get_department: {
method: 'department.get',
params: {
ID: '$result[get_user][UF_DEPARTMENT]',
},
},
}, (result) => {
if (result.get_user.error() || result.get_department.error())
{
if (result.get_user.error())
{
console.error(result.get_user.error());
}
if (result.get_department.error())
{
console.error(result.get_department.error());
}
}
else
{
const departmentNumber = result.get_department.data().length;
let message = prepareMessage(result.get_user.data().NAME, result.get_user.data().LAST_NAME, departmentNumber);
for (let i = 0; i < departmentNumber; i++)
{
message += i === 0 ? '' : ', ';
message += result.get_department.data()[i].NAME;
}
alert(message);
}
}, true);
});
How to Use Examples in Documentation