SharePoint-2013
How to Get All Users From Site Group in SharePoint 2013 Using REST API
How to populate a drop down with all the users from a Site Group in SharePoint 2013 on premise Using REST API

In this article you will see how to get all the users from a site group using the REST API in SharePoint 2013 Online.

Introduction

SharePoint 2013 introduces a Representational State Transfer (REST) service that is comparable to the existing SharePoint client object models. Share point allows the developers to interact remotely with SharePoint data using any technology that supports REST web requests. Developers can perform Create, Read, Update, and Delete (CRUD) operations.

From their apps for SharePoint, solutions, and client applications, they are using REST web technologies and standard Open Data Protocol (OData) syntax. In this article, you will see the following.

  • Create an app using NAPA Tool in SharePoint 2013 Online.
  • Cross-Domain Requests.
  • Get all the users from the host site group using the REST API.

Source Code:

<script src=”../SiteAssets/jquery-1.11.3.js”></script>
<script type=”text/javascript”>
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + “/_api/web/sitegroups/getByName(‘GroupName’)/users”,
type: “GET”,
headers: {“accept”: “application/json;odata=verbose”},
success: function (data){
if (data.d.results)
{
for (var i = 0; i < data.d.results.length; i++) {

//Loop through all users and binding in dropdown
if (data.d.results[i] != null && data.d.results[i] != undefined) {
if ($(“#ddlGroup option[value='” + data.d.results[i] + “‘]”).length == 0) {
$(‘#ddlGroup’).append($(“<option/>”, {
value: data.d.results[i].Email,
text: data.d.results[i].Title
}));
}
}
}
}
},
error: function (error) {
alert(JSON.stringify(error));
}
});
</script>

Summary

Thus in this article you saw how to get all the users from a site group using the REST API in SharePoint 2013 Online.

For any query or solution you can contact us or email us for solution. Check our website for more such content.