Read Microsoft Teams messages using Graphs API
Explained the same in Youtube Video : https://youtu.be/Uez9QrBNNS0
So today I had a requirement to create a custom app where I can read all MS teams message and use AI to reply to the team’s messages.
The 1st thing we need is to get read all Messages in Microsoft Teams using a Graphs API. I tried to look for option and finally got a Teams Beta API named ‘messages (Without replies) in a channel’ but it needs GroupID and ChannelID to read to the messages.
![](https://itfreesupport.com/wp-content/uploads/2024/01/TeamsMsg-1024x523.jpg)
So I ran below Graphs API to get all the Teams I am members of, here we will get the name and the ID of the Teams group as well.
https://graph.microsoft.com/v1.0/me/joinedTeams
![](https://itfreesupport.com/wp-content/uploads/2024/01/TeamsMsg2-1-1024x674.jpg)
Now we need to use the Group ID in below graphs query to get allchannels in that teams group.
https://graph.microsoft.com/beta/teams/{group-id-for-teams}/Allchannels/
![](https://itfreesupport.com/wp-content/uploads/2024/01/TeamsMsg3-1-1024x577.jpg)
Finally when we have both the Group ID and ChannelID, we will use below graphs API to get all the messages in the ChannelID.
Note: I am only able to see all the unread messages.
https://graph.microsoft.com/beta/teams/{group-id-for-teams}/channels/{channel-id}/messages
![](https://itfreesupport.com/wp-content/uploads/2024/01/TeamsMsg4-1024x547.jpg)
Below I am able to see all the same messages using GUI in teams
![](https://itfreesupport.com/wp-content/uploads/2024/01/TeamsMsg5-1024x463.jpg)