B24Hook object is intended exclusively for use on the server.- A webhook contains a secret access key, which MUST NOT be used in client-side code (browser, mobile app).
- For the client side, use
B24Frame.
Quick Overview
To save memory, use fetchListMethod — the method returns an asynchronous generator for iterating through large lists. It doesn't count the total number of records.
The method returns an AsyncGenerator with the response data.
// Basic usage
import { B24Hook } from '@bitrix24/b24jssdk'
const $b24 = B24Hook.fromWebhookUrl('https://ваш_домен.bitrix24.ru/rest/1/webhook_код/')
try {
for await (const chunk of $b24.fetchListMethod('crm.item.list', {
entityTypeId: 2, // Entity type ID (e.g., 2 for Company)
select: ['id', 'title']
}, 'id', 'items')) {
$logger.info(`Items received [${chunk.length}]`, { chunk })
}
} catch (error) {
$logger.error('some error', { error })
}
Method Signature
fetchListMethod<T = unknown>(
method: string,
params: {
order?: any
filter?: any
[key: string]: any
},
idKey?: string,
customKeyForResult?: string | null
): AsyncGenerator<T[]>
Parameters
Return Value
AsyncGenerator<T[]> — возвращает данные ответа API.
Key Concepts
Optimized pagination without counting
fetchListMethod uses a special optimization for quickly retrieving large data volumes:
- Disabling total count: Uses the
start: -1parameter, which disables the calculation of the total number of items, significantly speeding up request execution. - Filtering by ID: After receiving each page of data, the method updates the filter, adding a condition
'>ID': lastIdto get the next batch of data. - Automatic completion: The process continues until an empty response is received.
Important Limitations
- Mandatory sorting by ID: The method requires that the sorting order by the ID field be specified in the parameters (e.g.,
order: { id: 'asc' }). This is necessary for the filtering to work correctly.
Error Handling
In case of an error, the method throws an exception.
try {
for await (const chunk of $b24.fetchListMethod('some.method', {}, 'id', 'items')) {
$logger.info(`Items received [${chunk.length}]`, { chunk })
}
} catch (error) {
$logger.error('some error', { error })
}
Examples
Getting all companies with filtering
Export all deals with the specific stage and the date of stage change.
Task processing
Alternatives and Recommendations
- For batch operations: Use
callBatchto execute up to 50 commands in a single request. - When you need the total item count: Use the regular
callMethodwith manual pagination. - To get the entire list in memory: Use
callFastListMethod, which returns the entire array of data. - On the client (browser): Use the built-in
B24Frameobject instead ofB24Hook.
References
- Official Bitrix24 REST API Documentation — Reference for all available methods.
- Working with Large Volumes of Data — Recommendations for optimizing code to retrieve large data.
callFastListMethod
Use `B24Hook.callFastListMethod()` to quickly fetch all list items from the Bitrix24 REST API. The method automatically performs all necessary requests to retrieve the complete dataset using an optimized approach that does not count the total number of items, significantly speeding up the process when working with large data volumes. Works only in server environment.
callBatch
Use B24Hook.callBatch() to execute batch requests to the Bitrix24 REST API. This allows you to execute up to 50 different commands in a single HTTP request, significantly increasing performance for bulk data operations. Works only in server environment.