環境
PowerShell 5.1.14409.1012
Mattermost 4.8.0
PowerShellのスクリプト
$loginResponse = Invoke-WebRequest -Uri "http://localhost:8065/api/v4/users/login" -Method POST -Body '{"login_id":"yourID","password":"yourPassword"}'
$token = $loginResponse.Headers.Token
$utf8PostBody = [System.Text.Encoding]::UTF8.GetBytes('{"channel_id":"xxxxxxxxxxxxxxxxxxxxxxxxxx","message":"出社!"}')
Invoke-WebRequest -Uri "http://localhost:8065/api/v4/posts" -Method POST -Body $utf8PostBody -Headers @{"Authorization" = "Bearer $token"}
- http://localhost:8065 :仮のMattermostサーバのパス。
- channel_id :WebGUIのチャンネル名をクリックし、情報を表示するを選択し確認する。
- [System.Text.Encoding]::UTF8.GetBytes() messageに全角文字を指定したさいに文字化けさせないため記述。