SharePoint Rest API: Create or Update SharePoint Groups Details

sharepoint rest api create sharepoint group

This SharePoint rest api tutorial explains, how to create a group using rest api in SharePoint Online or SharePoint 2013/2016. We will also discuss, how to update SharePoint group details using rest api in SharePoint Online/2013/2016.

If you are new to rest api, then check out SharePoint rest api tutorial and examples.

SharePoint deveopment training course

Create a group using Rest API in SharePoint 2013/2016/Online

Below is the SharePoint rest api code to create a SharePoint group in SharePoint Online or SharePoint 2013/2016 using rest api.

Put the below code inside a script editor web part or content editor web part in a web part page in SharePoint. Once you will click on the button it will create the SharePoint group.

<script src="http://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";
$.ajax({
url: requestUri,
type: "POST",
data:JSON.stringify({'__metadata': { 'type': 'SP.Group' }, 'Title': 'MyTest Group', 'Description':'My Group Description'}),
headers: {
"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest":$("#_REQUESTDIGEST").val()
},
success: onSuccess,
error: onError
});
function onSuccess(data) {
alert('Group created successfully');
}
function onError(error) {
alert(JSON.stringify(error));
}
});
});
</script>
<input type="button" id="btnClick" value="Create SharePoint Group"/>

Once you will create on the button, the group will be created like below:

sharepoint rest api create sharepoint group
sharepoint rest api create sharepoint group

Update SharePoint group details using Rest API

Below is the rest api code to update SharePoint group details using Rest API in SharePoint 2013/2016 or SharePoint Online. We can add the code inside a script editor or content editor web part in a web part page in SharePoint.

<script src="http://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(3838)";
$.ajax({
url: requestUri,
type: "POST",
data:JSON.stringify({'__metadata': { 'type': 'SP.Group' }, 'Description':'My New Updated Group Description'}),
headers: {
"content-type": "application/json;odata=verbose",
"X-HTTP-Method":"MERGE"
},
success: onSuccess,
error: onError
});
function onSuccess(data) {
alert('Group description updated successfully');
}
function onError(error) {
alert(JSON.stringify(error));
}
});
});
</script>
<input type="button" id="btnClick" value="Update SharePoint Group Details"/>

You may like following SharePoint rest api tutorials:

Hope this SharePoint tutorial helps to create a SharePoint group using rest api, as well as we saw how to update sharepoint group details using rest api in SharePoint.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →