// Chatworkの送信先ルームID
$room_id = '000000';
// APIトークン
$api_token = '*********';
// ファイルの設定
$file = new CURLFile('./file.xml', 'text/xml', 'filename.xml');
// Laravelの場合
// $file = new \CURLFile('./file.xml', 'text/xml', 'filename.xml');
// メッセージの設定
$message = 'メッセージ';
$options = array(
CURLOPT_URL => 'https://api.chatwork.com/v2/rooms/'.$room_id.'/files',
CURLOPT_HTTPHEADER => [
'X-ChatWorkToken: '. $api_token,
'Content-Type: multipart/form-data'
],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'message' => $message,
'file' => $file,
],
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
参照
https://developer.chatwork.com/ja/endpoint_rooms.html#POST-rooms-room_id-files