You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Zoho Writer API与cURL合并PDF时遇参数配置错误求助

解决Zoho Writer API合并PDF时“Upload Parameters not configured properly”错误

错误原因分析

出现该错误的常见原因包括:

  • CurlFile未指定正确的MIME类型,导致API无法识别上传文件格式
  • files参数命名格式不符合API要求,Zoho Writer API更适配files[]而非索引式的files[0]/files[1]
  • output_settings未生成合法的JSON字符串,或参数格式不符合API规范

修正后的代码示例

$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$upload_url = "https://zohoapis.com/writer/api/v1/documents/pdf/combine";

// 生成合法的output_settings JSON字符串
$output_settings = json_encode([
    'name' => 'CombinedFile.pdf'
]);

// 构造请求数据:使用files[]参数名,明确指定PDF的MIME类型
$data = [
    'output_settings' => $output_settings,
    'files[]' => new CurlFile("download/test2.pdf", "application/pdf"),
    'files[]' => new CurlFile("download/test1.pdf", "application/pdf"),
];

$header = [
    'Authorization: Zoho-oauthtoken ' . $token
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // 建议开启SSL验证提升安全性
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);

// 捕获cURL传输错误,便于调试
if (curl_errno($ch)) {
    die('Curl 请求错误: ' . curl_error($ch));
}

$response = curl_exec($ch);
curl_close($ch);

$response_data = json_decode($response, true);
// 使用print_r/var_dump输出响应,避免echo数组导致的显示问题
print_r($response_data);

额外调试建议

  • 验证文件路径有效性:用file_exists("download/test1.pdf")和is_readable("download/test1.pdf")确认文件存在且PHP有读取权限
  • 检查令牌权限:确保Zoho OAuth令牌拥有Writer.documents.ALL或对应PDF合并操作的权限
  • 查看完整响应信息:如果仍报错,输出完整JSON响应,里面会包含更具体的参数错误提示

内容的提问来源于stack exchange,提问作者Ashwani Rai

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 14:53:10