0

I am trying remove user from Sharepoint group using Rest API.I have tried the below code but it is not getting any error but the user is not removing from the group.Please help me to find out what i am doing wrong in the code.Thanks in advance.

principal ID is the ID of the user and roledefid is the id of the sharepoint contribute group.

function revokePermission(webURL,listTitle,userID)
{
    debugger;
    try {
        var roleID=1073741827;
        jQuery.ajax({
            url: webURL + "/_api/Web/roleassignments/removeroleassignment(principalid="+userID+",roledefid="+roleID+")",
            method: "POST",
            headers: { 
                "Accept": "application/json;odata=verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                'X-HTTP-Method': 'DELETE'
            },
            success: function (data) {
                debugger;
                var userGroups= data.d.Member;
                userGroups.deleteObject();
            },
            error: function (data) {
                htmlContent+="<td></td></tr>";
                console.log(data);
            }
        });
    } catch (e) {
        console.log(e);
    }
}
1

1 Answer 1

0

RoleAssigments isnt group, the right url to romeve user from group is:

webURL + "/_api/web/sitegroups/getbyname('"+groupName+"')/users/removeByLoginName";

and the post data should be like:

data: JSON.stringify(
    {
        "__metadata": {
            "type": "SP.User"
        },
        "LoginName": loginName
    }
)

Your Answer

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

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