Всем привет.
Я пытаюсь создать новый лид с помощью кода:
$url = "https://mysite/api/leads";
$data = array(
"name" => "John Doe",
"email" => "john.doe@example.com",
"phone" => "1234567890",
"company" => "Example Inc.",
"source" => "New Site",
"status" => "New"
);
$data_json = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authtoken: ".$api_key
));
$response = curl_exec($curl);
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($status_code == 201) {
echo "New lead created successfully.";
} else {
echo "Error creating new lead. Status code: ".$status_code;
}
Но CRM возвращает ответ:
"status": false,
"error":
{ "name":"The Lead Name field is required.",
"source":"The Source field is required.",
"status":"The Status field is required."
},
"message": "The Lead Name field is required. The Source field is required. The Status field is required."
}
Я не понимаю, где ошибка в моем коде. Запрос основан на
документации.