I am trying to create the New Lead via RESTAPI but getting error
`<?php
$api_key = "mytoken";
$url = "https://crm.mydomain.fr/api/leads";
$inputData = array(
"name" => "John Doe",
"email" => "john.doe@example.com",
"phonenumber" => "1234567890",
"assigned" => "",
"tags" => "",
"address" => "123 Example Street",
"city" => "Example City",
"default_language" => "",
"description" => "This is a test lead",
"source" => "New Site", // Ensure this is a valid source in your CRM
"status" => 1 // Ensure this is a valid status ID in your CRM
);
$cleanedRequest = array(
"url" => "https://mydomain.com/api/leads",
"method" => "POST",
"body" => $inputData,
"headers" => array(
"Content-Type: application/json",
"authtoken" => $api_key
)
);
$data_json = json_encode($cleanedRequest['body']);
$curl = curl_init($cleanedRequest['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);
echo "Response: ".$response."\n";
echo "Status Code: ".$status_code."\n";
if ($status_code == 201) {
echo "New lead created successfully.";
} else {
echo "Error creating new lead. Status code: ".$status_code;
echo "\nResponse: ".$response;
}
`
but always got {
"status": false,
"error": {
"name": "The Lead Name field is required.",
"source": "The Source field is required.",
"status": "The Status field is required."
},
"message": "<p>The Lead Name field is required.</p>\n<p>The Source field is required.</p>\n<p>The Status field is required.</p>\n"
}