E
E
Egor_Zhurawski2020-08-18 23:03:27
Bitrix24
Egor_Zhurawski, 2020-08-18 23:03:27

Why is the name not added to the lead in Bitrix24?

Using the rest api, I'm trying to add a lead to Bitrix 24 ..
The title and phone number are added to the lead, but the name does not want .. What could be the problem?

$nameStart = $_POST["nameStart"];
$phoneStart = $_POST["phoneStart"];
$pos = "Заявка с сайта";

// формируем URL в переменной $queryUrl
$queryUrl = 'https://домен/rest/6/идентификатор/crm.lead.add.json';
 // формируем параметры для создания лида в переменной $queryData
$queryData = http_build_query(array(
  "fields" => array(
    'TITLE' => $pos, // НАЗВАНИЕ
    'NAME' => $nameStart , // ИМЯ
    'OPENED' => 'Y', // Доступно для всех
'SOURCE_ID' => "WEB", //Источник вебсайт
    //"ASSIGNED_BY_ID" => 1,  Ответственный
    "PHONE" => array(array("VALUE" => $phoneStart, "VALUE_TYPE" => "WORK" )),
  ),
  'params' => array("REGISTER_SONET_EVENT" => "Y")
));

  // обращаемся к Битрикс24 при помощи функции curl_exec
$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, 1);
if (array_key_exists('error', $result)) echo "Ошибка при сохранении лида: ".$result['error_description'].
"<br/>";

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilia Malashko, 2020-08-19
@miv-men

Maybe you have a custom field with a name?
There are several ways to find this out.
For example:
1. Go to any lead
2. Open the console (press F12)
3. Select the "Name" field and see what id
If the default name should really be NAME:
5f3c8de31d355759492650.png
If the name field was added manually, then the id will be of the following form :
5f3c8e1b0a976745160756.png

D
Dima Pozdnyakov, 2020-09-02
@tutdiscoteca

Check if your $nameStart variable is empty. Also, all required parameters must be specified. Try adding SECOND_NAME. It is also mandatory.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question