问题描述
我正在研究Zoho Projects API.发送HTTP帖子时,我有一个API密钥.发送发帖请求时出现错误.
I am working on Zoho Projects API. I have got an API key when sending an HTTP post. While sending the post request I am getting an error.
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"}}
A solution is mentioned here. But it's not helping me anymore.
Zoho自己提供了一个 PHP示例,我正在使用.
Zoho its self is providing a PHP Example that I am using.
更新1
好吧,我在curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request_parameters));
之后添加了$request_url .= '?' . http_build_query($request_parameters);
然后再次检查响应.该网址在
Ok, I added $request_url .= '?' . http_build_query($request_parameters);
after curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request_parameters));
and then again checked the response. The URL is below
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
.
There is +
Sign in between the spaces which is causing a problem. There should be empty spaces in between the words. Like Meter+No+002999000368_Site+Comm+Issue
should be Meter No 002999000368_Site Comm Issue
.
如何摆脱此错误.任何帮助将不胜感激.
How to get rid of this error. Any help would be highly appreciated.
推荐答案
如果上面的代码是您真正使用的代码,则可能必须将$request_url
中的[PORTALID]
更改为您分配的实际门户ID. ,
If the above code is what you exactly used then you might have to change the [PORTALID]
in the $request_url
to the actual portal id that you have assigned,
$request_url ='https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/'.$proj_id.'/bugs/?';
请参见 here
如何获取portal_id
.
编辑
由于将空格编码到+
中而出现问题,这是由于 http_build_query()
,您可以在$request_parameters
中使用urlencode()
作为标题,以便它使用%20
而不是+
尽管规则说
As you are having the problem due to the encoding of the spaces into +
which is due to the encoding used by http_build_query()
, you can use urlencode()
for the title inside the $request_parameters
so that it uses %20
instead of +
although the rules say that
You should have %20 before the ? and + after.
You should have %20 before the ? and + after.
否则,如果API仍然不允许您在'title' =>urlencode('Meter No '.$msn.'_'.$issue_name),
中删除空格
otherwise, you might have to remove the spaces from the 'title' =>urlencode('Meter No '.$msn.'_'.$issue_name),
if the API does not allow you anyhow
$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,
);
这篇关于如何解决Zoho Project API常规错误6500?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!