Cannot post a message with bot to public or private channel using API

Summary
I cannot post a message with bot to public or private channel using API

Steps to reproduce

  1. Mattermost version 9.4.2, self-hosted, Database Schema Version: 117, Build Number: 7586560796
  2. I created a bot account with System Admin role
  3. Using API, this bot account can create channels, can post direct messages, list channels, list posts, but cannot post messages to Public or Private channels

Expected behavior
The following should create a message in channel id y5rt8g79ojgodeibtewdrs4njw

curl --location 'https://mm.mycompany.com/api/v4/posts' \
--header 'X-Requested-With: XMLHttpRequest' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer thisisatoken' \
--data '{
    "channelId": "y5rt8g79ojgodeibtewdrs4njw",
    "message": "Hello world"
}'

Observed behavior
I receive this message instead

{
  "id":"api.context.permissions.app_error",
  "message":"You do not have the appropriate permissions.",
  "detailed_error":"",
  "request_id":"jguqn1rsd7yt7bqyinaqooeoac",
  "status_code":403
}

Please am I missing something?

I just tried with mattermost-preview docker image Mattermost Version: 9.5.0. The same.

curl --location 'http://localhost:8065/api/v4/posts' \
--header 'X-Requested-With: XMLHttpRequest' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer hfayeezxm3yuumro9xok7ju7uy' \
--data '{
    "channelId": "mwrwoefugpnfiqhu9ut4zjo3xw",
    "message": "Hello world"
}'

Hi PavelK,

Thanks for reaching out on the Mattermost Community Forum and sharing the step-by-step details of your issue – this is really helpful in diagnosing what’s going wrong!

Based on the observed behavior you shared, it appears the api.context.permissions.app_error and status code 403 point to a potential permissions issue. You mentioned you created a bot account with System Admin role. Even though the bot has System Admin roles, it will only have the permissions ascribed to the roles assigned to it in System Console > User Management > Bots.

Please ensure that your bot has the create_post and create_post_public permissions. You can check this under System Console > User Management > Permissions > System Role > Bot > Send Messages > Create Posts and Send Messages > Create Public Posts.

Also, please verify if “Enable integrations to override usernames” and “Enable integrations to override profile picture icons” are enabled in System Console > Integrations > Integration Management.

If after checking and updating these settings you continue to encounter difficulties, please let us know. We’re here to help until you’ve got your bot posting messages as intended!

Best Regards,
~Mattermost AI Assistant :robot:

[Disclaimer: This was an AI assisted response powered by Mattermost AI. Were any of the above suggestions inaccurate? Let us know by replying to this comment!]