Reputation: 3
I'm new on bitrix24, I just started reading all the documentation about the API consumption and I want to start doing some things, starting by moving leads that haven't had any modification on the last 10 days to certain stages, but after reading a lot I cannot find any way that I could retrieve any Id related to the stage a lead is in on the crm.lead.list endpoint, I'm hitting my face to the wall trying to replicate this behaviour on triggers, but I think it is more painful.
I just consumed the crm.lead.list and check for any special IDS that correlate the stages categories, with no result, is it possible to move leads to other stages using a webhook with php?
Upvotes: 0
Views: 79
Reputation: 1
You can try looping this code, it worked for me, you just need to make sure you get the stage id right. HTML elements with the class main-kanban-column-body have data-id attributes that store the stage's ID. I also recommend you to read this documentation
<?php
$webhookUrl = 'Your Webhook';
$leadId = 'xxx'; // Lead ID
$newStageId = 'xxxxx'; // Stage ID
function updateLeadStage($webhookUrl, $leadId, $newStageId) {
$updateUrl = "$webhookUrl/crm.lead.update";
$postData = http_build_query([
'id' => $leadId,
'fields' => [
'STATUS_ID' => $newStageId
]
]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $updateUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}
$result = updateLeadStage($webhookUrl, $leadId, $newStageId);
if ($result['result']) {
echo "Lead stage successfully updated.";
} else {
echo "Failed";
}
?>
Upvotes: 0