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();
       clientContext.executeQueryAsync(this.onQuerySucceeded, this.onQueryFailed);      

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

  • What access do you have on the site and on the groups ?
    – Ravi
    Nov 18 '19 at 6:29
  • on the group: group owner ;site: the site owner
    – Harrish
    Nov 18 '19 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 '19 at 9:30

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.

  • Did not work, same error 'Acces Denied'
    – Harrish
    Nov 18 '19 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 '19 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 '19 at 9:32
  • Still did not work
    – Harrish
    Nov 18 '19 at 9:38

Need to check the Group settings.

enter image description here

I think it will work.

  • 1
    Thanks, It's working. Nov 18 '19 at 13:30
  • it works in sharepoint but not when its done through jsom in the angular app
    – Harrish
    Nov 19 '19 at 4:37
  • Sorry, I have tested in SPFx with react. Nov 19 '19 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 '19 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 '19 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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