2016-07-22 47 views
0

所以我按照http://developer.servicem8.com/docs/how-to-guides/attaching-files-to-a-job-diary/的步驟在ServiceM8中添加一個PDF到工作日記。 我有點失落,爲什麼最後一步不工作。我已將附件添加到作業,並在標題中返回了UUID。我已經提取了UUI,然後使用curl和下面的代碼;如何「提交文件附件」到ServiceM8中的作業?

$service_url="https://api.servicem8.com/api_1.0/Attachment/9640887b-df46-4bfb-a47c-4afb20ed3d6b.file"; 
$curl = curl_init(); 
$curl = curl_init($service_url); 
curl_setopt($curl, CURLOPT_USERPWD, "[email protected]:[email protected]"); 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_HEADER, 1); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
$curl_response = curl_exec($curl); 

我得到一個 「HTTP/1.1 400 BAD_REQUEST的Content-Length:0連接:關閉」 作爲迴應 - 任何想法,我做錯了嗎?

回答

0

看起來你實際上沒有發佈任何文件內容,即你的請求試圖附加一個空文件。

假設您的PDF保存在/tmp/cool_document.pdf

$service_url="https://api.servicem8.com/api_1.0/Attachment/9640887b-df46-4bfb-a47c-4afb20ed3d6b.file"; 
$file_data = file_get_contents("/tmp/cool_document.pdf"); // read the file contents from disk 

$curl = curl_init($service_url); 
curl_setopt($curl, CURLOPT_USERPWD, "[email protected]:[email protected]"); 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_POST, true); // This configures CURL to send a HTTP POST 
curl_setopt($curl, CURLOPT_POSTFIELDS, $file_data); // This puts your PDF file in the body of the HTTP request 
curl_setopt($curl, CURLOPT_HEADER, 1); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
$curl_response = curl_exec($curl); 
+0

真棒 - 這是它:)我已經張貼到文件的引用,以下的答案,通過ServiceM8客戶支持支持請求。 –