get members of a group graph pnp js
To get the members of a group using the Ember.js framework and the PnP JS library, you can follow these steps:
- Import the necessary modules:
javascript
import { sp } from 'sp-pnp-js';
- Use the
get
method from the PnP JS library to retrieve the members of the group. You will need to provide the group's ID or name as a parameter:
javascript
const groupId = 1; // Replace with the actual group ID or name
const members = await sp.web.siteGroups.getById(groupId).users.get();
This code retrieves the group using its ID (or name) and then gets the list of users in that group.
- You can now use the
members
variable to access the list of group members and perform any further operations you need.
Here is the complete code snippet:
import { sp } from 'sp-pnp-js';
const groupId = 1; // Replace with the actual group ID or name
const members = await sp.web.siteGroups.getById(groupId).users.get();
This code imports the necessary modules, retrieves the group members, and stores them in the members
variable.