2016-07-22 5 views
0

ServiceM8の仕事日記にPDFを追加するには、http://developer.servicem8.com/docs/how-to-guides/attaching-files-to-a-job-diary/の手順に従ってください。 最後のステップがうまくいかない理由について少し迷っています。私は仕事に添付ファイルを追加し、UUIDをヘッダーに戻しました。私はそのUUIを抽出した後、カールと次のコードを使用して抽出しました。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の顧客サポートを通じてサポート要求に答え、次の、ファイルへの参照を掲示していました。 –

関連する問題