Edit on GitHub

Use Mattermost REST APIs with Apps

Apps frequently need to call the Mattermost API in order to perform actions as the bot user or as the current user accessing the app.

The Apps framework exposes the Mattermost REST API, both directly through HTTP calls and for Golang developers via a driver that makes interacting with the Mattermost server easier and more convenient.

For example, the Mattermost REST API documentation shows how to call Mattermost AddChannelMember API here

Authorization of Mattermost REST API calls in Apps 

An authorization token is required when invoking the Mattermost API via HTTP. The token must be set in the Authorization header as a bearer token. This bearer token can be either the bot_access_token to make the call as the bot, or the acting_user_access_token to make the call as the current user access the app.

Calling the Mattermost REST API via the Golang Driver 

Golang developers can also call the Mattermost AddChannelMember API via the Golang driver using the following code.

For example, the Golang driver appclient package includes a Client struct which implements the Mattermost Server’s client library. The following code creates an instance of the Client struct and adds a bot to a channel in response to a call:

// Create an instance of the REST API client, acting as a bot (vs. a user)
client := appclient.AsBot(callRequest.Context)
// Add the bot to the channel with ID `channelId`
channelMember, response, err := client.AddChannelMember(channelId, callRequest.Context.BotUserID)
if err != nil {
    // handle the error

Did you find what you were looking for?

Thank you! We appreciate your feedback.

Tell us more

Your feedback helps us improve the Mattermost developer documentation.

Have a feature request? Share it here.

Having issues? Join our Community server.