Skip to main content

Quick-start with curl

Examples

Copy-pasteable requests for the most common operations. Replace your-mattermost-server.com with your server URL and <TOKEN> with a valid personal access token.

Log in and get a session token

curl -i -X POST https://your-mattermost-server.com/api/v4/users/login \
-H 'Content-Type: application/json' \
-d '{
"login_id": "user@example.com",
"password": "yourpassword"
}'

The session token is returned in the Token response header.

Post a message to a channel

curl -X POST https://your-mattermost-server.com/api/v4/posts \
-H 'Authorization: Bearer <TOKEN>' \
-H 'Content-Type: application/json' \
-d '{
"channel_id": "<CHANNEL_ID>",
"message": "Status update from API"
}'

Create a channel

curl -X POST https://your-mattermost-server.com/api/v4/channels \
-H 'Authorization: Bearer <TOKEN>' \
-H 'Content-Type: application/json' \
-d '{
"team_id": "<TEAM_ID>",
"name": "ops-incident-2026-05",
"display_name": "Ops Incident — 2026-05",
"type": "O"
}'

Add a user to a channel

curl -X POST https://your-mattermost-server.com/api/v4/channels/<CHANNEL_ID>/members \
-H 'Authorization: Bearer <TOKEN>' \
-H 'Content-Type: application/json' \
-d '{ "user_id": "<USER_ID>" }'

Upload a file

curl -X POST https://your-mattermost-server.com/api/v4/files \
-H 'Authorization: Bearer <TOKEN>' \
-F 'channel_id=<CHANNEL_ID>' \
-F 'files=@./report.pdf'

Trigger a slash command

curl -X POST https://your-mattermost-server.com/api/v4/commands/execute \
-H 'Authorization: Bearer <TOKEN>' \
-H 'Content-Type: application/json' \
-d '{
"channel_id": "<CHANNEL_ID>",
"command": "/echo Hello from the API"
}'