How To Create Deal From External Services Using Webhook?

How To Create Deal From External Services Using Webhook?

Today we will see how to check contact which already exist in Bitrix:

If exist then create New deal with existing contact.

If Not exist then create contact and deal associate with it.

Step 1 

First we need to genrate key using webhook. To genrate key:

Applications->Web Hooks->Add web hook->inbound webhook->click CRM checkbox->Save

Step 2 

Then Add following code in your website contact us page.

<?php

function writeToLog($data, $title = ”) {

$log = “\n————————\n”;

$log .= date(“Y.m.d G:i:s”) . “\n”;

$log .= (strlen($title) > 0 ? $title : ‘DEBUG’) . “\n”;

$log .= print_r($data, 1);

$log .= “\n————————\n”;

file_put_contents(getcwd() . ‘/hook.log’, $log, FILE_APPEND);

return true;

}

 

$defaults = array(‘first_name’ => ”, ‘last_name’ => ”, ‘phone’ => ”, ’email’ => ”);

$email=$_POST[’email’];

$email=array($email);

$id=array(‘type’=>’EMAIL’,’values’=>$email,’entity_type’=>’CONTACT’);

if (array_key_exists(‘saved’, $_REQUEST)) {

$defaults = $_REQUEST;

writeToLog($_REQUEST, ‘webform’);

 

$queryUrl = ‘https://yourbitrix_domain/rest/1/webhook_key/crm.duplicate.findbycomm’;

$queryData = http_build_query($id);

$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);

For Customized Business Solutions at best prices Contact Us now