简体   繁体   中英

Unable to run the Rest API Using Php and Curl

I had created Zoho API which was using Version one now they migrate into Version two, My version 1 php code which is using curl function is working perfectly fine which is mention below,

<?php
$auth="a5014536e7303c218e983f9b2da7ae00";
$xml= "
<Leads>
<row no="1">
<FL val="City">Chennai</FL>
</row>
</Leads>
";
$result = insert($auth,$xml);
print_r($result);

function insert($auth,$xml)
{
$curl_url ="https://crm.zoho.in/crm/private/xml/Leads/insertRecords";
$curl_post_fields= "authtoken=".'$auth'.&scope=crmapi&xmlData=".$xml."";
$ch = curl_int();
curl_setopt( $ch, CURLOPT_URL, $curl_url);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt( $ch, CURLOPT_TIMEOUT,60);
curl_setopt( $ch, CURLOPT_POST,1);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER,true);
curl_setopt( $ch, CURLOPT_POSTFIELDS,$curl_post_fields);
$response= curl_exec($ch);
curl_close($ch);
return $response;
}
?> 

But when i migrate to Version Two By using ZOHO Documention API Documentation 1API Documentation 2 It wont run i dont know why some times it gives White Screen Error Some times 500 Error below is the Version 2 Code.

<?php
   $apiUrl = "https://www.zohoapis.com/crm/v2/Leads/";

$fields = json_encode(array("data" => array(["City" => "Egham"])));

$headers = array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($fields),
    'Authorization: Zoho-oauthtoken 4869c41171910edf553c07461c59a059',

);


$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$response = curl_exec($ch);
curl_close($ch);
return $response;
?>

Can any one tell me what i am doing wrong or can help me with modify the code?

Replace the API URL from

$apiUrl = "https://www.zohoapis.com/crm/v2/Leads/";

to

$apiUrl = "https://www.zohoapis.com/crm/v2/Leads";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM