docs/api/examples.mdx
<Eyebrow>Examples</Eyebrow>
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.
curl -i -X POST https://your-mattermost-server.com/api/v4/users/login \
-H 'Content-Type: application/json' \
-d '{
"login_id": "[email protected]",
"password": "yourpassword"
}'
The session token is returned in the Token response header.
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"
}'
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"
}'
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>" }'
curl -X POST https://your-mattermost-server.com/api/v4/files \
-H 'Authorization: Bearer <TOKEN>' \
-F 'channel_id=<CHANNEL_ID>' \
-F 'files=@./report.pdf'
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"
}'