I'm using the "Create a modern team site" using the PnP/PnPjs, and I want to add a user to the "Members" group of the newly created site.
I tried using this code:
let memberGroup = siteTitle + " " + "Members"
console.log("Trying to get group: " + memberGroup)
console.log("Adding user: " + expLoginName)
let web = new Web(targetSiteUrl);
let group = web.siteGroups.getByName(memberGroup)
group.users.add(expLoginName).then(function (d) {
d.select("Id").get().then(userData => {
console.log(userData);
});
});
But I get an error message saying that it can't find the group. Is the group not available before a couple of minutes after the site is created? or am I doing something wrong?
UPDATE: GetById(5)
worked, might change to GetByName()
later if I figure out the correct way