Goal : Send Microsoft Teams Chat message from Magic xpi using Microsoft Graph API
1/ Define Authorization "ChatMessage.Send" under Microsoft Graph API in Azure Portal (Delegate authorization is mandatory)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT3-1024x402.png)
2/ Get the conversation id from the Teams URL
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT4-1024x571.png)
(*) if you dont see the id in the URL, disable “Nouveau Teams” (“New teams”)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT11-1024x219.png)
(**) Or you can do this
Open Microsoft NEW Teams and navigate to the chat you want to get the Chat ID for.
Click on the three dots (…) next to one of the message . and copy the link and past on your note pad
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_MG2.png)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_MG3-1024x53.png)
3/ Check that you can send a message using Postman with your credentials
Fill the Authorization TabControl with all relevant information (clientid, secret, …)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT1-1-1024x781.png)
The URL must be in the format : https://graph.microsoft.com/v1.0/chats/<conversation id>/messages
exemple : https://graph.microsoft.com/v1.0/chats/19:3a12f010-cf21-488c-948a-2041bda4e04c_9037358c-987a-4368-94c4-ad256a9a7629@unq.gbl.spaces/messages
Set the json body with : {“body”: {“content”: “<text message>”}}
Check that the reponse is 201 Created
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT2-1024x574.png)
4/ Define a REST Magic xpi Resource with OAuth2 and press the “Access Token” Button
Verify that you can get an access token and verify that the refresh token is available.
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT5-1-1024x537.png)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT7-1-1024x467.png)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT8-1-1024x447.png)
5/ Define a path on the Magic xpi Resource by pressing “Paths” button
The path must be in the format : /chats/{id}/messages
where {id} corresponds to the teams conversation id
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT6-1-1024x458.png)
6/ Drag & Drop a REST Client component to make a Post on /chats/{id}/messages
set the conversation id
set the DataBlob with the Json Message
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT9-1024x607.png)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT10-1024x447.png)
![](https://france.magicsoftware.com/blog/wp-content/uploads/2024/04/TEAMS_CHAT4-1024x571.png)
That’s all Folks.