### WebSocket Hello Event Structure Source: https://developers.mattermost.com/api-documentation An example of a 'hello' event received after successful WebSocket authentication. It includes the server version and broadcast information. ```json { "event": "hello", "data": { "server_version": "3.6.0.1451.1c38da627ebb4e3635677db6939e9195" }, "broadcast":{ "omit_users": null, "user_id": "ay5sq51sebfh58ktrce5ijtcwy", "channel_id": "", "team_id": "" }, "seq": 0 } ``` -------------------------------- ### Get Current User Source: https://developers.mattermost.com/api-documentation Retrieves the profile of the currently authenticated user using a session token or personal access token. ```APIDOC ## GET /users/me ### Description Retrieves the profile information for the currently authenticated user. This endpoint can be accessed using a session token or a personal access token. ### Method GET ### Endpoint /api/v4/users/me ### Parameters #### Headers - **Authorization** (string) - Required - Bearer token for authentication (e.g., `Bearer YOUR_TOKEN`). - **Cookie** (string) - Optional - `MMAUTHTOKEN` cookie value for authentication (e.g., `MMAUTHTOKEN=YOUR_TOKEN`). ### Request Example Using Authorization Header: ```bash curl -i -H 'Authorization: Bearer ckh3t4knu3fzujt76o57f5jo4w' http://localhost:8065/api/v4/users/me ``` Using Cookie: ```bash curl -i -H 'Cookie: MMAUTHTOKEN=ckh3t4knu3fzujt76o57f5jo4w' http://localhost:8065/api/v4/users/me ``` ### Response #### Success Response (200) - **User Object** (object) - The user object of the currently logged-in user. #### Response Example ```json { "id": "user_id", "create_at": 1610000000000, "update_at": 1610000000000, "delete_at": 0, "username": "testuser", "first_name": "Test", "last_name": "User", "email": "someone@nowhere.com", "auth_service": "" } ``` ``` -------------------------------- ### WebSocket API Request: User Typing Source: https://developers.mattermost.com/api-documentation Send this JSON to the WebSocket to indicate that a user has started typing in a channel or thread. The 'seq' field should be incremented for each request. ```json { "action": "user_typing", "seq": 2, "data": { "channel_id": "nhze199c4j87ped4wannrjdt9c", "parent_id": "" } } ``` -------------------------------- ### WebSocket API Error Response Source: https://developers.mattermost.com/api-documentation An example of an error response from a WebSocket API request. It includes a status of 'FAIL' and an 'error' object with an ID and message. ```json { "status": "FAIL", "seq_reply": 2, "error": { "id": "some.error.id.here", "message": "Some error message here" } } ``` -------------------------------- ### User Login Source: https://developers.mattermost.com/api-documentation Authenticates a user by providing their login credentials and optionally an MFA token. Returns a session token upon successful login. ```APIDOC ## POST /users/login ### Description Authenticates a user with their login credentials. The `login_id` can be an email, username, or AD/LDAP ID. An optional MFA `token` can be provided. ### Method POST ### Endpoint /api/v4/users/login ### Parameters #### Request Body - **login_id** (string) - Required - The user's login identifier. - **password** (string) - Required - The user's password. - **token** (string) - Optional - The Multi-Factor Authentication token. ### Request Example ```json { "login_id": "someone@nowhere.com", "password": "thisisabadpassword" } ``` ### Response #### Success Response (200) - **Token** (string) - The session token for authentication. - **User Object** (object) - The user object of the logged-in user. #### Response Example ```json { "id": "user_id", "create_at": 1610000000000, "update_at": 1610000000000, "delete_at": 0, "username": "testuser", "first_name": "Test", "last_name": "User", "email": "someone@nowhere.com", "auth_service": "" } ``` ``` -------------------------------- ### Authenticate with Session Token (Authorization Header) Source: https://developers.mattermost.com/api-documentation After obtaining a session token, include it in the Authorization header with the 'Bearer' method for subsequent API requests. ```bash curl -i -H 'Authorization: Bearer ckh3t4knu3fzujt76o57f5jo4w' http://localhost:8065/api/v4/users/me ``` -------------------------------- ### Login with Session Token (cURL) Source: https://developers.mattermost.com/api-documentation Use this cURL command to log in to the Mattermost API using a session token. Provide the user's login ID and password in the JSON body. Note the Windows-specific cURL syntax for escaping quotes. ```bash curl -i -d '{"login_id":"someone@nowhere.com","password":"thisisabadpassword"}' http://localhost:8065/api/v4/users/login ``` ```bash curl -i -d "{\"login_id\":\"someone@nowhere.com\",\"password\":\"thisisabadpassword\"}" http://localhost:8065/api/v4/users/login ``` -------------------------------- ### Authenticate with Session Token (Cookie) Source: https://developers.mattermost.com/api-documentation Alternatively, use the session token as the MMAUTHTOKEN cookie value for API authentication. ```bash curl -i -H 'Cookie: MMAUTHTOKEN=ckh3t4knu3fzujt76o57f5jo4w' http://localhost:8065/api/v4/users/me ``` -------------------------------- ### WebSocket Connection and Authentication Source: https://developers.mattermost.com/api-documentation Connect to the Mattermost WebSocket endpoint and authenticate using standard API methods or an authentication challenge. ```APIDOC ## WebSocket Connection and Authentication ### Description Connect to the Mattermost WebSocket at `/api/v4/websocket` using a standard WebSocket opening handshake. Authentication can be handled via cookies (for browser-based sessions) or an explicit `Authorization` header. For authentication challenges, send a JSON payload with `action: "authentication_challenge"` and your token. ### Method GET (for initial connection) ### Endpoint `/api/v4/websocket` ### Authentication Challenge Example ```json { "seq": 1, "action": "authentication_challenge", "data": { "token": "mattermosttokengoeshere" } } ``` ### Success Response Example ```json { "status": "OK", "seq_reply": 1 } ``` Upon successful authentication, a `hello` event with server version information will be received. ``` -------------------------------- ### Rate Limit Headers Source: https://developers.mattermost.com/api-documentation These headers indicate your current rate limit status for API requests. They specify the maximum requests allowed, remaining requests in the current window, and when the limit resets. ```http X-Ratelimit-Limit: 10 X-Ratelimit-Remaining: 9 X-Ratelimit-Reset: 1441983590 ``` -------------------------------- ### WebSocket Authentication Challenge Source: https://developers.mattermost.com/api-documentation Send this JSON to authenticate with the Mattermost WebSocket using a token. Ensure the token is valid. ```json { "seq": 1, "action": "authentication_challenge", "data": { "token": "mattermosttokengoeshere" } } ``` -------------------------------- ### WebSocket API Actions Source: https://developers.mattermost.com/api-documentation Perform actions via the WebSocket connection by sending JSON payloads with an `action` field. ```APIDOC ## WebSocket API Actions ### Description Interact with the Mattermost server through the WebSocket connection by sending JSON messages with an `action` field specifying the desired operation. A sequence number (`seq`) should be included and incremented for each request to help correlate responses. ### Available Actions * `user_typing` * `get_statuses` * `get_statuses_by_ids` ### Example: User Typing Request ```json { "action": "user_typing", "seq": 2, "data": { "channel_id": "nhze199c4j87ped4wannrjdt9c", "parent_id": "" } } ``` ### Success Response Example ```json { "status": "OK", "seq_reply": 2 } ``` ### Error Response Example ```json { "status": "FAIL", "seq_reply": 2, "error": { "id": "some.error.id.here", "message": "Some error message here" } } ``` ``` -------------------------------- ### Authenticate with Personal Access Token Source: https://developers.mattermost.com/api-documentation Personal access tokens can be used for authentication by including them in the Authorization header with the 'Bearer' method, similar to session tokens. These tokens do not expire unless revoked. ```bash curl -i -H 'Authorization: Bearer 9xuqwrwgstrb3mzrxb83nb357a' http://localhost:8065/api/v4/users/me ``` -------------------------------- ### WebSocket Authentication Success Response Source: https://developers.mattermost.com/api-documentation This is the expected JSON response upon successful WebSocket authentication. It confirms the sequence number of the challenge. ```json { "status": "OK", "seq_reply": 1 } ``` -------------------------------- ### WebSocket API Success Response Source: https://developers.mattermost.com/api-documentation A standard 'OK' response to a WebSocket API request. The 'seq_reply' field matches the 'seq' of the original request. ```json { "status": "OK", "seq_reply": 2 } ``` -------------------------------- ### Standard API Error Response Structure Source: https://developers.mattermost.com/api-documentation All errors from the Mattermost API return an appropriate HTTP status code and a JSON body containing details about the error. ```json { "id": "the.error.id", "message": "Something went wrong", // the reason for the error "request_id": "", // the ID of the request "status_code": 0, // the HTTP status code "is_oauth": false // whether the error is OAuth specific } ``` -------------------------------- ### Rate Limit Exceeded Error Response Source: https://developers.mattermost.com/api-documentation When you exceed the API rate limit, a '429 Too Many Requests' status is returned with headers indicating the limit has been reached and a body message. ```http HTTP/1.1 429 Too Many Requests Date: Tue, 10 Sep 2015 11:20:28 GMT X-RateLimit-Limit: 10 X-RateLimit-Remaining: 0 X-RateLimit-Reset: 1 limit exceeded ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.