Question

How to retrieve Microsoft 365 security groups/members inside an SPFX web part?

Does anybody know how to do this or know of any tutorials? I am searching the internet with no luck.

enter image description here

Was it helpful?

Solution

The code below will list all the members of a office 365 security group or any group. The Group ID ({dab8006b-95f1-4df2-8704-004667d4b491}) is found by going into Azure > Groups.

Main component:

this.props.context.msGraphClientFactory
        .getClient()
          .then((client: MSGraphClient) => {
            client.api('https://graph.microsoft.com/v1.0/groups/{dab8006b-95f1-4df2-8704-004667d4b491}/members')
            .get((error, response:any, rawResponse?: any) => {
              console.log('Graph', error);
              console.log('Graph', response);
            });
            });
      };

Package-solution.json:

 "webApiPermissionRequests": [
      {
        "resource": "Microsoft Graph",
        "scope": "Directory.Read.All"
      }
    ]
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top