1

Find, Add and update the data using lead machine API with Curl and php. And you need to use your own ApiKey and MachineId.you can also use the jQuery and XML for this task

you need to use your own api key and MachineId/

function httpPost($url,$params)
{
   $postData = ''; 
   if($params!='')
   {
       $postData = json_encode($params);
   } 
    $ch = curl_init();   // init the curl
    curl_setopt($ch,CURLOPT_URL,$url); // pass the request URL
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HEADER, false);
    if($params!='')
    {
        curl_setopt($ch, CURLOPT_POST, count($postData));
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 
    }
    $headers = array();
    $headers[] = 'X-Apple-Tz: 0';
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Accept: application/json';
    $headers[] = 'X-MachineId: 565cf0f246287c6236000053';
    $headers[] = 'X-ApiKey: xFfayRvtK7dyzIynReibr2SChUKMIcrypCiDfCR553w';
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);  // create a custom header 
    $output=curl_exec($ch);
    curl_close($ch);
    return $output;
}
if( isset( $_POST ["Field19"] ))
{
$params = array(
   "contact" => array(
   "first_name" => $_POST['Field19'],
   "last_name" => $_POST['Field20'],
   "tags"=> array(
      "acutweb"
    ),  
   "_parent_mobile" => $_POST['Field6'],
   "_parent_last_name" => $_POST['Field23'],
   "_parent_first_name" => $_POST['Field22'],
   "primary_email" => array(
                "email"=> $_POST['Field9'],
                "email_type"=> "string"
   ),
    "primary_address" => array(
                "line1"=> $_POST['Field25'],
                "postcode"=> $_POST['Field26'],
                "suburb"=> $_POST['Field27']
   )
)
);
    $femail = $_POST['Field9'];
    $femail =urlencode($femail);
    $url ="https://www.leadmachine.com/api/v2/contacts/find_by_contact_email?email=".$femail."&expand_assigned=true"; //check data by email id 
    $emailchk =  httpPost($url,"");
    if($emailchk==200)
        {    
         echo $finaldata = httpPost("https://www.leadmachine.com/api/v2/contacts/upsert_by_contact_email?email=".$femail."&expand_assigned=true",$params); //update data by email id 

 }
 else
 {
     echo $finaldata = httpPost("https://www.leadmachine.com/api/v2/contacts?expand_assigned=true",$params);  // For add new entry 

 }
}

0 Answers0