MS Graph API - MS Teams channel last updated/last message

Copper Contributor

Hi,

we want to do a report of all our Teams and Channels.

With that it would be nice to get when it was lastly updated/used so we could do some cleanup afterwards.

 

Via Powershell and also GraphaAPI check i know that channels do not save data of when they have been lastly updated, the only chance I have is to use GraphAPI and check messages for similar data.

 

This call https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/messages should help me out BUT it always returns with 403. I have all needed permissions consented (as I am global admin in our tenant), I have correct ID's added (checked with checking the channel and returning details of the channel). Request token is valid.

 

Graph Explorer screenshot

 

MS Teams API export is one of the possible option but since I need to check way long in the past, it is limited by retention policy. I really just need to get last message (not the text, but just details about it) from each channel to get a "time stamp" of last activity.

Ideally when and who.

 

Can you please help me out?
Thank you

3 Replies
Are you a member of the team/channel? When using the Graph explorer (or the delegate permissions flow as a whole), you only have access to the set of teams/channels the user under which identity you are running is able to access.
Hmm.. I've just tested this. As I am using privileged account (for role segregation) to which I have Global Administrator it seems I must have membership to each team and possibly to each channel to pull any message what so ever.
Am I blind or is it not written in documentation?

I then believe there must be some powershell or GraphAPI call to get me at least membership to all channels, even to private ones. Right?

Thank you!
That's simply how delegate permissions work - they give you access only to what the user himself is able to access. The alternative is to run with application permissions, without a user, which usually give you unrestricted access to all resources of the chosen type (as per the permissions granted).