Zoho API-V2添加Attactmetn URL

时间:2018-10-31 11:33:18

标签: php api curl zoho

我正在尝试在crm中添加附件网址。我正在流这个documentation。但是我出错了!

这是我的代码:

$zoho_url = "https://www.zohoapis.com/crm/v2/$module/$id/Attachments";
$post['attachmentUrl'] = $url;
$ch=curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_URL,$zoho_url);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
$headers = array(); 
$headers[] = "Authorization: ".$authtoken; 
$headers[] = "Content-Type: multipart/form-data"; 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

$response = curl_exec($ch); 
$err = curl_errno($ch);

curl_close ($ch);
if ($err) {
  $result = $err;
} else {
  $result = $response;
}

print_r($result);

这是答复:

{"code":"INVALID_REQUEST","details":{},"message":"unable to process your request. please verify whether you have entered proper method name, parameter and parameter values.","status":"error"}

1 个答案:

答案 0 :(得分:0)

我编写了这段代码,用于在zoho记录中附加文件。

    //Get the oauth Token
    $accessToken=getCurrentAccessToken();
    // files to upload
    $tmpfile;
    $filename;
    $type;
    foreach($files as $file){
        $tmpfile = $file['tmp_name'];
        $filename = basename($file['name']);
        $type = $file['type'];
    }
    $cfile = new CURLFile(realpath($tmpfile),$type,$filename);
    $post_data = array (
        'file' => $cfile
    );
    $url = "https://www.zohoapis.com/crm/v2/$module/$id/Attachments";

    $headers = array(
        'Content-Type: multipart/form-data',
        sprintf('Authorization: Zoho-oauthtoken %s', $accessToken)
    );
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    $response = curl_exec($ch);
    return $response;