使用来自 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, CURLOPT_POSTFIELDS, json_encode($entriesData));
$output = curl_exec($ch)
并获取错误响应:“message”:“发现额外 key ”,“status”:“失败”,“code”:9015,
我正在使用此代码来获取访问 token ,它运行良好
$data = [
'refresh_token' => $refreshToken,
'client_id' => $clientId,
'client_secret' => $secret,
'grant_type' => 'refresh_token'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://accounts.zoho.com/oauth/v2/token');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 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 编码的。
关于php - 无法通过 zoho api 上传文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67919265/