I tried to get Microsoft Teams users using the Graph API, but I am receiving the error message:
"Authorization has been denied for this request."
let URL = ${serviceUrl}v3/conversations/${channelId}/pagedmembers;
Note: I have granted the following permissions (both Delegated and Application):
TeamMember.Read.All
Group.Read.All
User.Read.All
I want to get all team members who belong to Microsoft Teams channels.
To get all team members who belong to specific Microsoft Teams channel, you can make use of below Microsoft Graph API call:
GET https://graph.microsoft.com/v1.0/teams/teamId/channels/channelId/members
Initially, get team ID by running below API call with at least Team.ReadBasic.All
Delegated permission in Graph Explorer:
GET https://graph.microsoft.com/v1.0/teams?$filter=displayname eq 'TeamName'
Response:
Now, use above team ID to get channel ID by running this API call with at least Channel.ReadBasic.All
Delegated permission:
GET https://graph.microsoft.com/v1.0/teams/teamId/channels?$filter=displayName eq 'ChannelName'
Response:
At last, you can run below API call to get all team members who belong to specific Microsoft Teams channel with at least ChannelMember.Read.All
Delegated permission:
GET https://graph.microsoft.com/v1.0/teams/teamId/channels/channelId/members
Response:
Make sure to add required permissions properly by granting admin consent to avoid "Access Denied" errors.
Reference: