如何使用销售订单附件API在Zoho Books中创建销售订单附件?

时间:2018-02-08 13:35:28

标签: php-curl zohobooks

我正在尝试使用销售订单附件API在Zoho Books中创建销售订单附件,但它给我的错误如" [code] => 33003 [message] =>没有附上收据"。

如果我尝试使用postman的API,那就可以了。

以下是我从postman复制的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;
 }

 ?>

感谢任何帮助。

1 个答案:

答案 0 :(得分: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);

?>