如何解决Zoho Project API一般错误6500?

时间:2018-02-20 09:28:22

标签: php rest post yii2 zoho

我正在研究Zoho Projects API。发送HTTP帖子时我有一个API密钥。在发送帖子请求时,我收到了错误。

API CALL CODE

$request_url ='https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/'.$proj_id.'/bugs/?';

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

$request_parameters = array(
'authtoken' => 'token',
'title' =>'Meter No '.$msn.'_'.$issue_name,
'assignee'=>$assigne_name,
'flag'=>'Internal',
'classification_id'=> $class_id,
'module_id'=>$module_id,
'severity_id'=>$sevr_id,
'CHAR2'=>$ref_no,
'LONG1'=>$msn,

 );

 curl_setopt($ch, CURLOPT_POST, TRUE);
 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request_parameters));

 /* Here you can set the Response Content Type */
 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
 /* Let's give the Request Url to Curl */
 curl_setopt($ch, CURLOPT_URL, $request_url);
 /*
 Yes we want to get the Response Header
 (it will be mixed with the response body but we'll separate that after)
 */
 curl_setopt($ch, CURLOPT_HEADER, TRUE);
 /* Allows Curl to connect to an API server through HTTPS */
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
/* Let's get the Response ! */
$response = curl_exec($ch);
/* We need to get Curl infos for the http_code */
$response_info = curl_getinfo($ch);
/* Don't forget to close Curl */
curl_close($ch);
/* Here we get the Response Body */
$response_body = substr($response, $response_info['header_size']);
// Response HTTP Status Code
echo "Response HTTP Status Code : ";
echo $response_info['http_code'];
echo "\n";
// Response Body
echo "Response Body : ";
echo $response_body;

我得到的回应是

Response HTTP Status Code : 400
Response Body : {"error":{"code":6500,"message":"General Error"}}

提到了一个解决方案here。但它不再帮助我了。

Zoho它的自我提供了我正在使用的PHP Example

更新1

好的,我在$request_url .= '?' . http_build_query($request_parameters);之后添加了curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request_parameters)); 然后再次检查响应。网址在

下面
https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/[PROJECTID]/bugs/?authtoken=key&title=Meter+No+002999000368_Site+Comm+Issue&assignee=Laar+Circle&flag=Internal&classification_id=1139168000000297069&module_id=1139168000000019372&severity_id=1139168000000007003&CHAR1=farhan_javaid&CHAR2=20372210038297U&LONG1=002999000368

导致问题的空格之间有+登录。单词之间应该有空格。与Meter+No+002999000368_Site+Comm+Issue类似Meter No 002999000368_Site Comm Issue

如何摆脱这个错误。任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:1)

如果您使用的是上述代码,那么您可能需要将[PORTALID]中的$request_url更改为您指定的实际门户网站ID,

$request_url ='https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/'.$proj_id.'/bugs/?';

请参阅here如何获取portal_id

修改

由于+将空格编码为由http_build_query()使用的编码引起的问题,因此您可以使用urlencode()作为$request_parameters内的标题{1}}所以它使用%20代替+,尽管规则说明了

<强> You should have %20 before the ? and + after.

否则,如果API无论如何不允许你,你可能必须从'title' =>urlencode('Meter No '.$msn.'_'.$issue_name),中删除空格

$request_parameters = array(
'authtoken' => 'token',
'title' =>urlencode('Meter No '.$msn.'_'.$issue_name),
'assignee'=>$assigne_name,
'flag'=>'Internal',
'classification_id'=> $class_id,
'module_id'=>$module_id,
'severity_id'=>$sevr_id,
'CHAR2'=>$ref_no,
'LONG1'=>$msn,

 );