Unable to send a chat message, via team and channel id, using Microsoft Graph

Tony Lockhart 106 Reputation points
2022-02-24T14:34:52.717+00:00

Hi All,

After attempting to send a chat message via Microsoft Graph API, I get the error below. However, my payload shows the message body is being sent (Please note I have erased token from screenshot). It appears that the server is rejecting my Post request because it can not parse the body, which is in json format. The exact same query runs fine in Graph Explorer. Can anyone provide any advise on fixing this issue?

177677-screen-shot-2022-02-24-at-101821-pm-1.png

177553-screen-shot-2022-02-24-at-92133-am.png

Here is a snippet of my options and endpoint for my Fetch post request:

const url = "https://graph.microsoft.com/v1.0/teams/5834e4c1-2897-4cc3-b274-91a091900b56/channels/19:1df3a1da1e9b48eeaba2ef3d2f61834f@thread.tacv2/messages";  
  
const options = {  
                  method: "POST",  
                  headers: {  
                    Authorization: `Bearer ${response.accessToken}`,  
                    "Content-type": "application/json",  
                  },  
                body: JSON.stringify({  
                    content: 'Hello Word'  
                    }),  
              };  
Microsoft Security | Microsoft Graph
{count} votes

Accepted answer
  1. Ramjot Singh 861 Reputation points Microsoft Employee
    2022-02-25T19:13:11.153+00:00

    Content is a property and not serialized as string.

       POST https://graph.microsoft.com/v1.0/teams/fbe2bf47-16c8-47cf-b4a5-4b9b187c508b/channels/19:4a95f7d8db4c4e7fae857bcebe0623e6@thread.tacv2/messages  
       Content-type: application/json  
         
       {  
         "body": {  
           "content": "Hello World"  
         }  
       }  
    

    Please refer to https://learn.microsoft.com/en-us/graph/api/chatmessage-post?view=graph-rest-1.0&tabs=http#example-1-send-a-hello-world-message-in-a-channel


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.