0

I am using SharePoint 2013 online.

We have SharePoint groups and there the group owner can successfully add or remove the users. But when accessing the user groups through JSOM in my angular app which deployed on SharePoint I get

ErrorCode: -2147024891 ErrorMessage: "Access denied. You do not have permission to perform this action or access this resource." ErrorTypeName: "System.UnauthorizedAccessException"

Here's the code I used to add users to SharePoint user group:

addUserJSOM() {
       const loginName = `i:0#.f|membership|${this.form.value.email}`;
       var clientContext = new SP.ClientContext.get_current();
       var siteGroups = clientContext.get_web().get_siteGroups();
       var web = clientContext.get_web();
       let spGroup = siteGroups.getByName('Team WhatIf');
       let user = web.ensureUser(loginName);
       var userCollection = spGroup.get_users();
       userCollection.addUser(user);
       clientContext.load(user);
       clientContext.load(spGroup);
       clientContext.executeQueryAsync(this.onQuerySucceeded, this.onQueryFailed);      
}

but the site administrator and access to adding or deleting user from user groups via JSOM.

3
  • What access do you have on the site and on the groups ?
    – Ravi
    Nov 18, 2019 at 6:29
  • on the group: group owner ;site: the site owner
    – Harrish
    Nov 18, 2019 at 9:23
  • is it necessary to be a site admin to add or remove users from user groups via rest API or jsom?
    – Harrish
    Nov 18, 2019 at 9:30

2 Answers 2

1

Goto group setting of 'Team WhatIf' and select everyone option for

Who can view the membership of the group?

and then try your above code.

4
  • Did not work, same error 'Acces Denied'
    – Harrish
    Nov 18, 2019 at 9:27
  • is it necessary to be a site admin to add or remove users from user groups via rest API or jsom?
    – Harrish
    Nov 18, 2019 at 9:30
  • again goto that group settings and Who can edit the membership of the group? select group members and try again Nov 18, 2019 at 9:32
  • Still did not work
    – Harrish
    Nov 18, 2019 at 9:38
1

Need to check the Group settings.

enter image description here

I think it will work.

5
  • 1
    Thanks, It's working. Nov 18, 2019 at 13:30
  • it works in sharepoint but not when its done through jsom in the angular app
    – Harrish
    Nov 19, 2019 at 4:37
  • Sorry, I have tested in SPFx with react. Nov 19, 2019 at 6:55
  • 1
    Found out the problem this was because of the site i was using the sites permission was messed up that was why jsom function did not work
    – Harrish
    Nov 21, 2019 at 8:28
  • @PalashKantiBachar the problem was on my site, the permission of the site was messed up, that was the reason why I was getting accessed denied
    – Harrish
    Nov 22, 2019 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.