How to post messages on a channel

Roman 0 Reputation points
2024-05-08T19:54:04.64+00:00

I have a multi-tenant Microsoft Teams tab app. I want it to post messages on a selected channel from my server.

I successfully receive the token using this endpoint:

https://login.microsoftonline.com/{TENANT_ID}/oauth2/v2.0/token

Then, I use the token to post a message using this endpoint:
https://graph.microsoft.com/v1.0/teams/{TEAM_ID}/channels/{CHANNEL_ID}/messages

However, in the response, I encounter the error:
"message": "Missing role permissions on the request. API requires one of 'Teamwork.Migrate.All'. Roles on the request 'Group.Selected'."

I have added many permissions, including 'Teamwork.Migrate.All', but it doesn't resolve the issue."

Screenshot 2024-05-08 at 3.48.05 PM

Does this API even work? I've been struggling with it for 3 days already.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,819 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yakun Huang-MSFT 625 Reputation points Microsoft Vendor
    2024-05-09T05:41:57.0166667+00:00

    Hi @Roman

    After my testing, it works fine, and the issue you're having may be that you don't get the token back after granting permission, or the value of the scope is wrong, below I share my testing process for your reference.

    The first is to grant app application permissions.

    1

    The next step is to get the token and pay attention to the value of the scope.

    2

    After successfully obtaining the token, you can parse the token in the jwt.ms, this is my parsing result.

    3

    However, for sending messages, you need to use delegated permissions, as application permissions are only used to import messages.

    Please use delegated permissions (ChannelMessage.Send), get a token through the Auth code flow, and send an email. Or it's easier to use Graph explorer.

    4

    For more information, please refer to this link:

    https://learn.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-1.0&tabs=http

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.