SharePoint Rest API: Remove User by login name or User ID from SharePoint Group

This SharePoint Rest API tutorial explains, how to remove a user by Login name or user id from a SharePoint security group using Rest API.

The rest api code will work in SharePoint 2013 or SharePoint 2016. If you are new to Rest API, check out SharePoint Rest API Tutorial and Examples.

Remove User by LoginName or User ID from SharePoint Group using Rest API

We can easily remove a user from SharePoint group by login name or by user id using Rest API in SharePoint Online or SharePoint 2013/2016.

You can use removeByLoginName(‘domain\username’) or removed(10) to remove the user from the SharePoint group. Here 10 is the id of the user. Check out this article to know how to get id of the user using Rest Api.

Put the below code inside a script editor web part or content editor web part. This will be a POST Rest API call.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(function(){
$("#btnClick").click(function(){
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups(2544)/users/removeByLoginName(‘domain\\username’)";
$.ajax({
url: requestUri,
type: "POST",
success: onSuccess,
error: onError
});
function onSuccess(data) {
alert(‘User Removed successfully’);
}
function onError(error) {
alert(JSON.stringify(error));
}
});
});
</script>
<input type="button" id="btnClick" value="Remove User from SharePoint Group"/>

Simillarly, if you want to remove user by id then the rest URL will be like below:

var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups(2544)/users/removebyid(10)";

Here 10 is the id of the user.

You may like following SharePoint Rest API tutorials:

Hope this will be helpful to remove a user from SharePoint group using rest api by using login name or user id in SharePoint Online/2013/2016.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>