我正在使用 Bitrix24 api 生成器导出我的数据,但似乎无法通过数组位置[]来过滤响应

问题描述 投票:0回答:1

Bitrix 仅在我的所有数据的数组列表中显示最多 50 个位置,这是由于安全问题而发生的,并且据我所知,无法更改。因此,要将数据从 Bitrix 导出到我的数据仓库(目前正在 Pentaho 内部进行转换),我需要获得接近 50.000 个数组(请记住,我一次只能获得 50 个!!!! -组织的 id 顺序)我需要帮助来过滤顺序中的 id,以便我的请求变得更容易。这些是我的参数:

打印

如果有人知道我可以使用什么样的选择或过滤器,我将非常感激!

arrays etl crm bitrix
1个回答
0
投票

尝试从图片中显示的窗口执行查询(如果图片将来离线,则从开发人员资源模板执行查询)并查看格式化结果。

对于大多数 Bitrix24 API 请求,响应(在本例中具有 10 个结果)将采用以下格式:

Array
   (
      [result] => Array
      (
         [0] => Array()
         [1] => Array()
         .....
         [9] => Array()

      [total] => 10
      [time] => Array()
)

但是,当有 50+ 个结果时,它看起来像这样:

Array
   (
      [result] => Array
      (
         [0] => Array()
         [1] => Array()
         .....
         [49] => Array()

      [next] => 50
      [total] => 12345
      [time] => Array()
)

添加[下一个]项是关键,因为您可以使用从下一个值开始的附加参数再次发送请求。对于 URL 查询字符串,这相当于在其末尾添加 &start=50。将其放入一个循环中,在返回 [next] 时运行,并在每次迭代时将 start 设置为 next 的值以获得所有结果。

我找到了一些旧代码作为示例。我相信这使用了 Guzzle (PHP),但它应该很容易适应您想要的任何内容。代码流程的注释比代码本身更重要。

do { //Need to run it at least once to determine if there is a 'next' or not
    $params = [
      'query' =>  
      [ 'order' => 
        [
          'ID' => 'ASC',
        ],
      'filter' => 
        [
           //you could put the DATE_CREATE filter here but it sounds like you may not want it. 
        ],
      'select' => 
        [
          'NAME',
          'LAST_NAME',
          'STATUS_ID',
          'EMAIL'
        ],
      'start' => [(isset($data['next']))? $data['next'] : 0], //in other words, if there is a 'next' in the response data, set start to the value of 'next'. If not (the first run) start at 0
]
     ]; 
  $response = $client->request('POST','crm.contact.list',$params); // Send a POST request using crm.contact.list with the parameters above
  $data = $response->getBody(); //get the response
  $data = json_decode($data, true); //decode the response
} while ($data['next']); //keep going while 'next' is returned. Remember, once there are less than 50, it won't be and you'll have it all. 

我不确定您是否仍然处于这种情况,但这肯定是我在开始使用 API 时偶然发现的事情,所以希望这个答案可以使您或将来的某人受益。

© www.soinside.com 2019 - 2024. All rights reserved.