Cannot create public/private channels with bot

Hi there,

I’m trying to create a bot for our Mattermost deployment.

Version: 5.15.0
Edition: Team

The endpoint I am trying to use is /api/v4/channels. I am successfully able to authenticate as the bot using a personal token and can submit my request. Unfortunately, I get the following response:

{ id: 'api.context.permissions.app_error',
  message: 'You do not have the appropriate permissions',
  detailed_error: '',
  request_id: '<redacted>',
  status_code: 403 }

The permission I need seems to be create_public_channel according to the API documentation. However, I cannot see anywhere in the UI to grant this to the bot.

Is anyone able to help shed some light on this? I imagine it also covers create_private_channel as well. The bot is able to successfully connect/authenticate/login with the token so I know it works. It can also receive messages and respond, so it’s working for the most part. I just need it to be able to create channels.

Thanks for the help!

1 Like

I am also having a similar issue. Are bots in Mattermost not allowed to create channels?

1 Like

Hi @frenbox , welcome to the Mattermost forums and sorry for the late reply!

A bot is allowed to create private and public channels, but it needs to be a member of the team you want to create the channel in first. By default, bot accounts are not assigned to any team, which is why the request is failing then.

Here’s an example on my system when the bot account I used is not assigned to any team:

# curl -sX POST -d '{ "team_id": "q44oy1r8s7ybxxo58zx4a5qmdr", "name": "bottestpublic", "display_name": "bottestpublic", "type": "O" }' -H "Authorization: Token mytoken" "https://mymattermost.tld/api/v4/channels" | jq .
{
  "id": "api.context.permissions.app_error",
  "message": "You do not have the appropriate permissions.",
  "detailed_error": "",
  "request_id": "yf9t988e1bbu5j1n8fm8rybqih",
  "status_code": 403
}

I did then add the bot account (test1234) to the team in question (test) using mmctl (you can also do that in the system console or using your team management):

mmctl --local team users  add test test1234

And after that, the channel creation worked:

# curl -sX POST -d '{ "team_id": "q44oy1r8s7ybxxo58zx4a5qmdr", "name": "bottestpublic", "display_name": "bottestpublic", "type": "O" }' -H "Authorization: Token mytoken" "https://mymattermost.tld/api/v4/channels" | jq .
{
  "id": "dien1ruybpd1zrftzbk3zz7awy",
  "create_at": 1678426582580,
  "update_at": 1678426582580,
  "delete_at": 0,
  "team_id": "q44oy1r8s7ybxxo58zx4a5qmdr",
  "type": "O",
  "display_name": "bottestpublic",
  "name": "bottestpublic",
  "header": "",
  "purpose": "",
  "last_post_at": 0,
  "total_msg_count": 0,
  "extra_update_at": 0,
  "creator_id": "sxw3nads8fdt9k976skqbo8jwy",
  "scheme_id": null,
  "props": null,
  "group_constrained": null,
  "shared": null,
  "total_msg_count_root": 0,
  "policy_id": null,
  "last_root_post_at": 0
}