I am trying to send a message to a chat using the graph api but i get 401 unauthorized

Yadav, Prakhar | RSI 20 Reputation points
2025-07-01T14:06:49.6466667+00:00

I have been trying to send a message on msteams using the graph api I am using this curl but I am getting 401- Unauthorized
curl 'https://graph.microsoft.com/v1.0/chats/XXX/messages' \

-H 'Accept: /' \

-H 'Accept-Language: en-GB,en-US;q=0.9,en;q=0.8' \

-H 'Authorization: Bearer token' \

-H 'Connection: keep-alive' \

-H 'Content-Type: application/json' \

-H 'Origin: https://developer.microsoft.com' \

-H 'Referer: https://developer.microsoft.com/' \

-H 'SdkVersion: GraphExplorer/4.0, graph-js/3.0.7 (featureUsage=6)' \

-H 'Sec-Fetch-Dest: empty' \

-H 'Sec-Fetch-Mode: cors' \

-H 'Sec-Fetch-Site: same-site' \

-H 'User-Agent: XXX \

-H 'cache-control: no-cache' \

-H 'client-request-id: XXX' \

-H 'pragma: no-cache' \

-H 'prefer: ms-graph-dev-mode' \

-H 'sec-ch-ua: "Google Chrome";v="137", "Chromium";v="137", "Not/A)Brand";v="24"' \

-H 'sec-ch-ua-mobile: ?0' \

-H 'sec-ch-ua-platform: "Windows"' \

--data-raw $'{\r\n"body": {\r\n"content": "Hello world"\r\n}\r\n}\r\n'

Kindly let me know what I am doing wrong
User's image

Microsoft Teams | Development
0 comments No comments
{count} votes

Accepted answer
  1. Gabriel-N 2,995 Reputation points Microsoft External Staff Moderator
    2025-07-02T01:00:45.67+00:00

    Hi Yadav, Prakhar | RSI

    Thank you for posting your question in the Microsoft Q&A forum. 

    I’ve conducted a test of the Microsoft Graph API in my development environment, and everything appears to be functioning correctly.

    User's image

    Below, I’ve outlined the steps I followed to successfully send a message to a Microsoft Teams chat, which may help you troubleshoot your issue: 

    1. Retrieve the Chat ID 
    GET https://graph.microsoft.com/v1.0/me/chats 
    
    

    From the response, identify and copy a valid chat ID. 

    1. Send a Message to the Chat 
    POST https://graph.microsoft.com/v1.0/chats/{chat-id}/messages 
    

    Replace {chat-id} with the actual ID from step 1. 

    Ensure that your application has been granted the following delegated permissions

    ChatMessage.Send 

    Chat.ReadWrite 

    Group.ReadWrite.All 

    These permissions are essential for sending messages to Teams chats. You can find detailed information about each permission here: Microsoft Graph permissions reference - Microsoft Graph | Microsoft Learn 

    If you're unsure how to configure permissions, please follow these steps: 

    User's image User's image

    If these permissions are not properly configured, you may encounter errors such as 401 Unauthorized or 404 Not Found when making API calls. 

    I hope these details help you resolve the issue.  

    Please understand that our forum is a public platform, and we will modify your question to cover your organization domain name in the description. Please notice to hide these personal or organization information next time you post error or some information to protect personal data. 


    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.  

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.