How to quickly get a lot of data from Bitrix24 via REST API

Often, when working with Bitrix24 REST API, it becomes necessary to quickly get the contents of certain fields of all elements of a list (for example, leads). The traditional way to do this is to contact the server through a method *.list



(for example, crm.lead.list



for leads) with a parameter select



listing the list of required fields. Moreover, the larger the list size and the more fields you upload, the longer the server takes to form a response.





Plus, due to the fact that the information is provided by the server page by page, there are several strategies for getting the entire list, and some of them allow you to speed up the process by orders of magnitude compared to sequential requests.





Strategies

Below we describe three strategies, which we tentatively named "ID filter", "Start increment" and "List + get".





The first two strategies ("ID filter" and "Start increment") are proposed in the official Bitrix24 documentation , but below we propose to "tighten" them.





ID filter

Requests are sent to the server sequentially with a parameter "order": {"ID": "ASC"}



(sorting in ascending order of ID), and each subsequent request uses the results of the previous one (filtering by ID, where ID> maximum ID in the results of the previous request).





start = -1



( total



), *.list



.





: , , ID . , , , throttling.





Start increment

, start



, .





, , , ( , start



, ).





, ( total



), .





, . ( 50 .) , .





24 REST API . .





, , . .





get_all()



fast_bitrix24



( - ).





List + get

, "Start increment" ID *.list



( , ID - 'select': ['ID']



) , *.get



ID. " " " ".





, ( ).





( crm.lead.list



) 3 ( "ID filter" - ID). 1, 50, 100 200 .





fast_bitrix24 24.





7- REST API ~35000 .





Getting 1 pages:
ID filter: 0.3 sec.
Start increment: 0.73 sec.
Getting ID list for the 'list+get' strategy, method crm.lead: 2.17 sec.

List + get: 2.61 sec.

Getting 50 pages:
ID filter: 12.8 sec.
Start increment: 21.39 sec.
List + get: 1.84 sec.

Getting 100 pages:
ID filter: 49.67 sec.
Start increment: 39.97 sec.
List + get: 3.28 sec.

Getting 200 pages:
ID filter: 99.67 sec.
Start increment: 78.05 sec.
List + get: 6.36 sec.
      
      



, , ("Start increment" "List + get"), .





, , "List + get" , , . (, 24 ?)





I'm not sure if there are high-level PHP libraries that allow the user to implement such strategies without bothering about packing requests into batches and organizing parallel requests with control of their speed. But if you write in Python, you are welcome to use fast_bitrix24



(see the page on Github ), which allows you to download data from Bitrix24 at a speed of up to thousands of elements per second.








All Articles