微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法通过 zoho api 上传文档

如何解决无法通过 zoho api 上传文档

使用来自 Laravel 的 curl 请求。

    $path =  storage_path('app/letters/letter.pdf');
    $post = '@' . $path;
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,'https://sign.zoho.com/api/v1/requests');
    $authorization = 'Authorization: Bearer ' . $zohoAccesstoken;
    curl_setopt($ch,CURLOPT_HTTPHEADER,[$authorization]);
    curl_setopt($ch,CURLOPT_CUSTomrEQUEST,"POST");
    curl_setopt($ch,CURLOPT_HEADER,0);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($post));
    $entriesData = ['data' => [
        'requests' => [
            'request_name' => "NDA ",'actions' => [
                'recipient_name' => 'test','recipient_email' => $mail,'action_type' => 'sign','verify_recipient' => false,],'is_sequential' => false,]
    ]];
    curl_setopt($ch,json_encode($entriesData));
    $output = curl_exec($ch)

并得到错误响应:"message": "Extra key found","status": "failure","code": 9015,

我正在使用此代码获取访问令牌,并且运行良好

        $data = [
            'refresh_token' => $refreshToken,'client_id' => $clientId,'client_secret' => $secret,'grant_type' => 'refresh_token'
        ];
        $ch = curl_init();
        curl_setopt($ch,'https://accounts.zoho.com/oauth/v2/token');
        curl_setopt($ch,0);
        curl_setopt($ch,$data);
        curl_setopt($ch,true);
        $output = curl_exec($ch);

解决方法

基于 API documentation 和这个 post,我认为这应该类似于:

$path =  storage_path('app/letters/letter.pdf');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'https://sign.zoho.com/api/v1/requests');
$authorization = 'Authorization: Bearer ' . $zohoAccessToken;
curl_setopt($ch,CURLOPT_HTTPHEADER,[$authorization]);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch,CURLOPT_HEADER,0); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,[
  'data' => json_encode([
    'requests' => [
      'request_name' => "NDA ",'actions' => [
        'recipient_name' => 'test','recipient_email' => $mail,'action_type' => 'sign','verify_recipient' => false,],'is_sequential' => false,]   
  ]),'file' => curl_file_create($path)
];
$output = curl_exec($ch);

这样,根据 API 文档,它似乎产生与 CURL 命令行调用大致相同的有效负载。

让我感到困惑的主要来源是 data 是字段的键,而相应的值是 JSON 编码的。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。