1

使用带有 Curl 和 php 的主机 API 查找、添加和更新数据。并且你需要使用你自己的 ApiKey 和 MachineId。你也可以使用 jQuery 和 XML 来完成这个任务

您需要使用自己的 api 密钥和 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 

 }
}
4

0 回答 0