How to send a teams 1-1 message from ms graph

Vagelis Dermos 0 Reputation points
2024-03-14T13:33:15.91+00:00

Hi to all,

i want to send a teams 1-1 message chat.

the steps i did so far.

  1. login from https://login.microsoftonline.com/ with clint id/secret scope=> https://graph.microsoft.com/.default
  2. create 1-1 chat
    https://graph.microsoft.com/v1.0/chats
    { "chatType":"oneOnOne", "members":[ { "@odata.type":"#microsoft.graph.aadUserConversationMember", "roles":["owner"], "******@odata.bind": "https://graph.microsoft.com/v1.0/users('7........f')" }, { "@odata.type":"#microsoft.graph.aadUserConversationMember", "roles":["owner"], "******@odata.bind": "https://graph.microsoft.com/v1.0/users('9........3')" } ] }

From the response, i take the "id" and post as :
https://graph.microsoft.com/v1.0/chats/19:7c82222.....paces/messages

{
  "body": {
     "content": "Hello world"
  }
}

but i take an error about migration

{
    "error": {
        "code": "Unauthorized",
        "message": "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.",
        "innerError": {
            "date": "2024-03-14T13:27:32",
            "request-id": "efee9ffb-28a6-4ffe-a398-57adec529133",
            "client-request-id": "efee9ffb-28a6-4ffe-a398-57adec529133"
        }
    }
}

In azure portal i have add several rights but no luck:
User's image

What am i missing?

Can anyone help me?

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

1 answer

Sort by: Most helpful
  1. Anonymous
    2024-03-15T01:55:09.2933333+00:00

    Hi @Vagelis Dermos

    Teams tag is mainly focused on the general issue of Microsoft Teams troubleshooting. According to your description, your question is related to Graph API, which is not in our support scope. The following suggestion is just for your reference:

    Send chat messages in channels or chats using Graph

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

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. *********************************************************************************************************


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.