Send a message to an existing group chat via Mircrosoft Graph

Mike Landi 20 Reputation points
2024-06-04T19:35:02.3066667+00:00

I have a test Teams tenant and have been exploring Microsoft Graph. I want to develop a .net app that can post messages into a group chat. When I try this in the test tenant, using the example from https://learn.microsoft.com/en-us/graph/api/chat-post-messages?view=graph-rest-1.0&tabs=http&source=docs, I get back a 401 with this as the message in the response: "Message POST is allowed in application-only context only for import purposes. Refer to https://docs.microsoft.com/microsoftteams/platform/graph-api/import-messages/import-external-messages-to-teams for more details."

I cannot figure out what this means and I see nothing in the online help that explains it. The link does not help. How do I send a message to a group chat?

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,627 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,461 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yakun Huang-MSFT 2,570 Reputation points Microsoft Vendor
    2024-06-05T01:43:50.2533333+00:00

    Hi @Mike Landi

    According to the Graph Api, Application permissions are only supported for migration. This error is therefore reported if you send a message while chatting with application permissions.

    User's image

    When sending a message in a chat, you need to use the delegation permissions ChannelMessage.Send or Group.ReadWrite.All, which will send the message in the chat on behalf of the logged in user, and you need to get a token through auth code flow when using the delegation permissions. You can refer to this document.

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful