代码之家  ›  专栏  ›  技术社区  ›  Moeez

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

  •  1
  • Moeez  · 技术社区  · 7 年前

    我正在开发Zoho项目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

    好的,我补充道 $request_url .= '?' . http_build_query($request_parameters); 之后 curl_setopt($ch, CURLOPT_POSTFIELDS, 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 .

    如何消除此错误。任何帮助都将不胜感激。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Community Mohan Dere    5 年前

    如果上面的代码是您实际使用的代码,那么您可能需要更改 [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 所以它使用 %20 而不是 + 虽然规则上说

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

    否则,您可能必须从 'title' =>urlencode('Meter No '.$msn.'_'.$issue_name), 如果API无论如何都不允许您

    $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,
    
     );