N
N
Nikita Grevtsov2017-06-01 20:29:05
PHP
Nikita Grevtsov, 2017-06-01 20:29:05

How to get the ID of a newly created lead (Bitrix24)?

Hello!
You need to create a lead with products. To add products to a lead, you need to know its ID.
I suppose it can somehow be pulled out of function(result). I just don't understand how to do it in php.
An example from the Bitrix documentation:

BX24.callMethod(
    "crm.lead.add", 
    {
        fields:
        { 
            "TITLE": "ИП Титов", 
            "NAME": "Глеб", 
            "SECOND_NAME": "Егорович", 
            "LAST_NAME": "Титов", 
            "STATUS_ID": "NEW", 
            "OPENED": "Y", 
            "ASSIGNED_BY_ID": 1, 
            "CURRENCY_ID": "USD", 
            "OPPORTUNITY": 12500,
            "PHONE": [ { "VALUE": "555888", "VALUE_TYPE": "WORK" } ] 
        },
        params: { "REGISTER_SONET_EVENT": "Y" }
    }, 
    function(result) 
    {
        if(result.error())
            console.error(result.error());
        else
            console.info("Создан лид с ID " + result.data());
    }
);

How do I add a lead:
<?
 $queryUrl = 'https://nagre.bitrix24.ru/rest/20/xxxxxxxxxxx/crm.lead.add.json';
 $queryData = http_build_query(array(
 'fields' => array(
 "TITLE" => $event_info["name"],
 "NAME" => $_POST["user_forms"][0]["name"],
 "LAST_NAME" => $_POST["user_forms"][0]["surname"],
 "STATUS_ID" => "NEW",
 "SOURCE_ID" => 3,
 "OPENED" => "Y",
 "ASSIGNED_BY_ID" => 20,
 "COMPANY_TITLE" => $_POST["user_forms"][0]["question1712473"],
 "POST" => $_POST["user_forms"][0]["question1712474"],
 "PHONE" => array(array("VALUE" => $_POST["user_forms"][0]["question1712472"], "VALUE_TYPE" => "WORK" )),
 "EMAIL" => array(array("VALUE" => $_POST["user_forms"][0]["mail"], "VALUE_TYPE" => "WORK" )),
 ),
 'params' => array("REGISTER_SONET_EVENT" => "Y")
 ));

 $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,
 ));
 curl_close($curl);
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem, 2017-06-02
@N_Grevtsov

class CB24{
  // выполнить метод rest api
  function method($auth, $method, $params){
    $c=curl_init('https://'.$auth['DOMAIN'].'/rest/'.$method);
    $params["auth"]=$auth['AUTH_ID'];
    curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($c,CURLOPT_POST,true);
    curl_setopt($c,CURLOPT_POSTFIELDS,http_build_query($params));
    $response=curl_exec($c);
    $response=json_decode($response,true);

    return $response;
  }
}
$CB24  = new CB24;
$cur_deal = $CB24->method($_REQUEST,'crm.lead.add.json',array(
  'fields'=>array(
    "TITLE" => 'test',
    )
    )
);

echo "<pre>";
print_r($cur_deal);
echo "</pre>";

Returns:
Array
(
[result] => 28
)
This is the id of the lead just created by the crm.lead.add method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question