Access denied when adding people to group on SharePoint onpremise RRS feed

  • Question

  • Hi All,

    I have been facing problem when I am adding a user to a SharePoint group via REST API. It is prompting for password for three times and then giving me the below error.

    {\"error\":{\"code\":\"-2147024891, System.UnauthorizedAccessException\",\"message\":{\"lang\":\"en-US\",\"value\":\"Access denied. You do not have permission to perform this action or access this resource.\"}}}

    But when I checked into my group the user was added successfully. It is very weird  to me.

    Below is my code example:


    var userAccountID = "domain\\username";
    var grpID = 107;

    function addUserToGrp(id, data){
           var url = _spPageContextInfo.webServerRelativeUrl + "_api/web/sitegroups("+ id +")/users"
    return jQuery.ajax({
                 url: url,
                 type: "POST",
                 data: JSON.stringify(data),
                 headers: {
    "accept": "application/json;odata=verbose",
           "X-RequestDigest": $("#__REQUESTDIGEST").val(),
           "content-Type": "application/json;odata=verbose"

    var item = {
         "__metadata": { "type": 'SP.User' },
         "LoginName": userAccountID

    addUserToGrp(grpID, item).done(function(){

    I am the site owner of the site and also I am the administrator of the group which ID, I have used in my example. And also I am able to add user to the group manually.

    Can anyone please help me out here with this.

    Appreciate your help. Thanks in advance.

    Thursday, March 30, 2017 3:05 PM

All replies