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

How to solve Zoho Project API General error 6500?

我正在处理 Zoho Projects API。我在发送 HTTP post 时得到了一个 API 密钥。发送 post 请求时出现错误。

API 调用代码

$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

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

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.

如何摆脱这个错误。任何帮助将不胜感激。

如果上面的代码正是您使用的,那么您可能需要将 $request_url 中的 [PORTALID] 更改为您分配的实际门户 ID,

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

查看 here 如何获得 portal_id

编辑

由于 + 的空格编码导致问题,这是由于 http_build_query() 使用的编码,您可以使用 urlencode() 作为标题$request_parameters 所以它使用 %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,

 );