0

我正在尝试使用销售订单附件 API 在 Zoho Books 中创建销售订单附件,但它给了我类似“[code] => 33003 [message] => Receipt not attach”的错误。

如果我用邮递员尝试 API,它就可以工作。

下面是我从邮递员那里复制的 API 调用。

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => 
"https://books.zoho.com/api/v3/salesorders/**********/attachment?
 organization_id=********",
 CURLOPT_RETURNTRANSFER => true,
 CURLOPT_ENCODING => "",
 CURLOPT_MAXREDIRS => 10,
 CURLOPT_TIMEOUT => 30,
 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
 CURLOPT_CUSTOMREQUEST => "POST",
 CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-
 Disposition: form-data; name=\"attachment\"; 
 filename=\"D:\\wamp\\www\\*****\\01-30-18 E01301811384413.pdf\"\r\nContent-
 Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--
 ",
 CURLOPT_HTTPHEADER => array(
 "Authorization: *********************",
  "Cache-Control: no-cache",
  "Content-Type: application/json",
 "Postman-Token: e1141774-32e0-09f1-059b-6d2ee0c44095",
 "content-type: multipart/form-data; boundary=----
 WebKitFormBoundary7MA4YWxkTrZu0gW"
 ),
 ));

 $response = curl_exec($curl);
 $err = curl_error($curl);

 curl_close($curl);

 if ($err) {
 echo "cURL Error #:" . $err;
 } else {
   echo $response;
 }

 ?>

任何帮助表示赞赏。

4

1 回答 1

0

邮递员生成的代码不适用于任何文件上传 API。

请尝试使用以下 php 代码片段将文件上传到 Zoho Books。

<?php

$file_name_with_full_path = '/Users/Admin/Desktop/1.png';

$request_url = 'https://books.zoho.com/api/v3/salesorders/******/attachment';

if (function_exists('curl_file_create')) { // php 5.6+
  $cFile = curl_file_create($file_name_with_full_path);
} else { // 
  $cFile = '@' . realpath($file_name_with_full_path);
}

$post = array(
    'authtoken' => '*******',
    'organization_id' => '*******',
    'attachment'=> $cFile);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 

$r = curl_exec($ch);
curl_close ($ch);
print_r($r);

?>
于 2018-07-16T11:05:53.607 回答