N
N
Niksss_7772021-06-15 12:49:33
Bitrix24
Niksss_777, 2021-06-15 12:49:33

Bitrix 24 cloud incoming webhook change lead field crm.lead.update?

Good afternoon, tell me how to change the value in one of the lead fields. I send the data from the newly created lead to the page with an outgoing webhook, where they are processed after that, one field must be changed by the incoming webhook. Please see what's wrong with the code.
I made two options , but unfortunately not one of them worked. (PS don't judge strictly, I'm just starting to code).

<?php
  
  $idDeal = $_REQUEST['data']['FIELDS']['ID'];
  
  $s = json_encode(sendDataToBitrix('crm.lead.get', array('ID' => intval($_REQUEST['data']['FIELDS']['ID']))), JSON_UNESCAPED_UNICODE);
  $decode = json_decode($s,true);

  $width  = array_column($decode, 'UF_CRM_1592376873160');
  $width  = current($width);
  
  $price1 = 96969;
  
  foreach($decode as $key => $value)
  {
      $value['UF_CRM_1621002264440'] = $price1 ;
      $decode[$key] = $value;   
  }
  
  
  function sendDataToBitrix($method, $decode) {
    $queryUrl = 'https://*********************ru/rest/22/***************5/' . $method ;
    $queryData = http_build_query($decode);
  
    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_SSL_VERIFYPEER => 0,
      CURLOPT_POST => 1,
      CURLOPT_HEADER => 0,
      CURLOPT_RETURNTRANSFER => 1,
      CURLOPT_URL => $queryUrl,
      CURLOPT_POSTFIELDS => $queryData,
    ));
  
    $result = curl_exec($curl);
    curl_close($curl);
    return json_decode($result, 1);
  }
  


 $deal_data = json_encode(addFields(), JSON_UNESCAPED_UNICODE);

$log = date('Y-m-d H:i:s') . ' ' . print_r($deal_data, true);

file_put_contents(__DIR__ . '/log888.txt', $log . PHP_EOL, FILE_APPEND);



  function addFields(){
    $dataFields  = sendDataToBitrix('crm.lead.update',
      [
       'ID'     => 277588,
       'fields' => [
        'STATUS_ID'   => 'IN_PROCESS ',
        'CURRENCY_ID' => 'RUB',
        'OPPORTUNITY' => '7778787'
      ], 
      'params' => ['REGISTER_SONET_EVENT' => 'Y'] 
      ]);
      return $dataFields;

  }

  
  
  ?>


Option two
<?php
  
  $idDeal = $_REQUEST['data']['FIELDS']['ID'];
  
  $s = json_encode(sendDataToBitrix('crm.lead.get', array('ID' => intval($_REQUEST['data']['FIELDS']['ID']))), JSON_UNESCAPED_UNICODE);
  $decode = json_decode($s,true);

  $width  = array_column($decode, 'UF_CRM_1592376873160');
  $width  = current($width);
  
  $price1 = 96969;
  
  foreach($decode as $key => $value)
  {
      $value['UF_CRM_1621002264440'] = $price1 ;
      $decode[$key] = $value;   
  }
  

  function sendDataToBitrix($method, $decode) {
    $queryUrl = 'https://***********.ru/rest/22/***************5/' . $method ;
    $queryData = http_build_query($decode);
  
    $curl = curl_init();
    curl_setopt_array($curl, array(
      CURLOPT_SSL_VERIFYPEER => 0,
      CURLOPT_POST => 1,
      CURLOPT_HEADER => 0,
      CURLOPT_RETURNTRANSFER => 1,
      CURLOPT_URL => $queryUrl,
      CURLOPT_POSTFIELDS => $queryData,
    ));
  
    $result = curl_exec($curl);
    curl_close($curl);
    return json_decode($result, 1);
  }
  

$str = leadUpdateById($decode,true);



$log = date('Y-m-d H:i:s') . ' ' . print_r($str, true);

file_put_contents(__DIR__ . '/log892.txt', $log . PHP_EOL, FILE_APPEND);


function leadUpdateById($decode){
    $queryData = http_build_query(array(
      'id' => $decode['ID'],
      'fields' => array(
        "NAME" => $decode['NAME'], 
        "UTM_SOURCE" => $decode['UTM_SOURCE'], //UTM метка
        "COMMENTS" => "Лид создан автоматически с сайта ".SITE_SERVER_NAME." - повторное обращение", //Комментарий
        "STATUS_ID" => "NEW", //Обновляем статус лида
        "DATE_MODIFY" => $decode['DATE'], //Обновляем стандартное поле даты модификации
      "UF_CRM_1621002264440" => "88888888", //Заполнение пользовательского поля
      ),
      'params' => array("REGISTER_SONET_EVENT" => "Y"), //Говорим, что требуется зарегистрировать новое событие и оповестить всех прчиастных
    ));
    
    $rest = 'crm.lead.update';
    
    $queryUrl = 'https://*************.ru/rest/22/**************5/'.$rest;
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
      CURLOPT_SSL_VERIFYPEER => 0,
      CURLOPT_POST => 1,
      CURLOPT_HEADER => 0,
      CURLOPT_RETURNTRANSFER => 1,
      CURLOPT_URL => $queryUrl,
      CURLOPT_POSTFIELDS => $queryData,
    ));
    
    $result = curl_exec($curl);
    
    curl_close($curl);
    
  $result = json_decode($result);
  
    return $result;
  }

  
  
  ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Kovalenko, 2021-08-12
@Niksss_777

$prms = array(
        "id" => $idLead,
        "fields" => array(
        "UF_CRM_1622919648" => 1,
    ),
);

$prms = json_encode( $prms );
$result = bx24( $prms, 'crm.lead.update' );

function bx24( $params, $type, $portal = '*', $admin_id = '*', $secret_code = '*' ) {

$queryUrl = 'https://' . $portal . '.bitrix24.ru/rest/' . $admin_id . '/' . $secret_code . '/' . $type;
$params = json_decode( $params, true );

$queryData = http_build_query(
    $params
);

$curl = curl_init();

curl_setopt_array( $curl, array(
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_POST           => 1,
    CURLOPT_HEADER         => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL            => $queryUrl,
    CURLOPT_POSTFIELDS     => $queryData,
) );

$result = curl_exec( $curl );

curl_close( $curl );
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question