LoginSignup
0
1

More than 3 years have passed since last update.

【PHP】ChatworkAPIを用いてファイルを送信する

Posted at
// 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

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1