Hello Glenn Maxwell,
Thank you for reaching out, Microsoft!
Use the following endpoint to list messages from a specific channel:
GET https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/messages
Replace {team-id} with your team ID and {channel-id} with the specific channel ID you want to export messages from.
Please follow the below steps:
Ensure Permissions:
- Verify that your Azure App registration has the necessary permissions. You mentioned
ChannelMessage.Read.All, which is correct for reading channel messages.
Get Access Token:
- You need an access token to authenticate your API requests. You can obtain this using the OAuth 2.0 authorization code flow. Here’s a quick guide on how to get an access token:
- Go to the Microsoft identity platform and follow the steps to get an access token.
List Channel Messages:
- Use the following endpoint to list messages from a specific channel:
GET https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/messages
Export Messages:
- To export the messages to a CSV file, here is sample PowerShell script:
$teamId = "111111-2222-3333-4444-5678956789" $channelId = "your-channel-id" $accessToken = "your-access-token" $headers = @{ "Authorization" = "Bearer $accessToken" } $messages = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/teams/$teamId/channels/$channelId/messages" -Headers $headers $messages.value | Export-Csv -Path "C:\path\to\your\file.csv" -NoTypeInformation
Please refer below documents for more details:
https://learn.microsoft.com/en-us/graph/api/resources/teams-api-overview?view=graph-rest-1.0
https://learn.microsoft.com/en-us/graph/auth-v2-user?tabs=http
I hope this helps!
If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment