【问题标题】:Zoho API-V2 Add Attactmetn URLZoho API-V2 添加 Attactmetn URL
【发布时间】:2019-04-04 13:29:16
【问题描述】:

我正在尝试在 crm 中添加附件 url。我正在流动这个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"}

【问题讨论】:

  • 我已经测试了你的代码,它非常适合我。可能问题与连接范围有关。
  • 感谢您的宝贵时间。我想在“Twilio”服务器中添加一个文件。我只有文件网址。我尝试将附件 url 添加到 CRM。那个案例我出错了!

标签: php api curl zoho


【解决方案1】:

我编写了这段代码用于在 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;

【讨论】:

    猜你喜欢
    • 2019-11-04
    • 1970-01-01
    • 2021-10-19
    • 2018-12-01
    • 2020-03-26
    • 2014-07-07
    • 2023-03-03
    • 2019-04-24
    • 2023-03-18
    相关资源
    最近更新 更多