繁体   English   中英

无法使用 PHP 和 Curl 运行 Rest API

[英]Unable to run the Rest API Using Php and Curl

我创建了使用版本一的 Zoho API,现在他们迁移到版本二,我使用 curl 函数的版本 1 php 代码运行良好,如下所述,

<?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;
}
?> 

但是当我迁移到版本 2 通过使用 ZOHO Documention API 文档 1API 文档 2它不会运行我不知道为什么有时它会出现白屏错误有时下面的 500 错误是版本 2 代码。

<?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;
?>

任何人都可以告诉我我做错了什么或可以帮助我修改代码吗?

将 API URL 替换为

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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