T
T
tokyodead2021-09-07 11:28:01
PHP
tokyodead, 2021-09-07 11:28:01

How to link a contact and a deal in Bitrix24 using the REST API?

Good afternoon, I'm new to PHP, tell me please, I add a contact and a deal, I take the data from the array that I received through the API, contacts are added, and deals too, how can I tie a contact with a deal?

// Функция добавления сделок
  function addDeal($res) {
    foreach($res['Items'] as $key => $value) {
      $dealData = sendDataToBitrix('crm.deal.add', [
        'fields' => [
          'TITLE' => 'Заявка,
          'STAGE_ID' => 'NEW',
          'CONTACT_ID' => $value['Id'],
        ], 'params' => [
          'REGISTER_SONET_EVENT' => 'Y'
        ]
      ]);
    }
    return $dealData;
  }
  // Функция добавления сделок

  // Функция добавления контактов
  function addContact($res) {
  foreach($res['Items'] as $key => $value) {
    $contactData = sendDataToBitrix('crm.contact.add', [
      'fields' => [
        'NAME' => $value['Data']['Name'],
        'OPENED' => 'Y',
        'PHONE' => ,
        'EMAIL' => ,
        'TYPE_ID' => 'CLIENT',
      ], 'params' => [
        'REGISTER_SONET_EVENT' => 'Y'
      ]
    ]);
  }
  return $contactData['result'];
  }
  // Функция добавления контактов


There is also a performance problem, the array is very large and the script takes a long time to process, how can this be improved? + The array is not processed to the end, it looks like the request limit of 60 seconds has been exceeded.
I dug into the documentation, so I did not understand anything.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2021-09-13
@gromdron

How can I link to a deal?

This is a flaw on the part of Bitrix24: it is impossible to link a contact with a deal through the rest api. We are waiting for REST API updates.
There is also a performance problem, the array is very large and the script takes a long time to process, how can this be improved?

Now you are doing synchronous requests 1 at a time. If it takes 1 second to process one request, then 60 requests = 60 seconds. You can group requests in batch , so 60 requests will turn into 2 requests and will be processed in ~2 seconds
. Also, I would recommend using a ready-made library for sending requests: https://github.com/mesilov/bitrix24-php-sdk/ tree/2.x

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question