I try to create a lead onto an existing organization.
I use the beneath function.
I get always a 400 bad request error (whatever is $titre and $orga) and i don’t figure out why.
$orga is the id of a previously created organization.
Nota: Same kind of code for creating organization works well.
function setLead($titre, $orga) {
$api_token = 'xxxxx';
$company_domain = 'xxxxx';
$url = 'https://' . $company_domain . '.pipedrive.com/api/v1/leads?api_token=' . $api_token;
$data = array(
'title' => $titre,
'organization_id' => $orga
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result != FALSE) {
echo json_encode (json_decode ($result), JSON_PRETTY_PRINT);
}
else {
echo "ERREUR setLead";
}
}