oauth-2.0azure-active-directorymicrosoft-graph-apimicrosoft-teamsmicrosoft-graph-teams

How can I "Get Microsoft Teams Users" Using of Microsoft Graph API


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):

  1. TeamMember.Read.All

  2. Group.Read.All

  3. User.Read.All

I want to get all team members who belong to Microsoft Teams channels.


Solution

  • 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:

    enter image description here

    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:

    enter image description here

    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:

    enter image description here

    Make sure to add required permissions properly by granting admin consent to avoid "Access Denied" errors.

    Reference:

    List members of a channel - Microsoft Graph