SharePoint Online And Office 365: Check Group Properties Using REST API
Welcome to an article on “How to Check Group Properties using REST API in SharePoint Online and Office 365” where we will see the steps of checking the group properties of a SharePoint group using REST API.
Open the “NAPA” Office 365 Development Tools through your SharePoint store.
Click on Add New Project.
It will ask you, what type of app do you want to build?
Select SharePoint Add-in and provide a name to your app and click on Create.
You will see the screen below on the app,
Click on Default.aspx and paste the code below under the “<asp:ContentContentPlaceHolderID=”PlaceHolderMain” runat=”server”>”.
Code
Group Properties
“text” value=“Group Name” id=“grouptextbox” />
“groupclick”>Check Group Properties
Now on the navigation click on the App.js file and paste the code below removing the previous code completely.
Code:
‘use strict’;
varhostweblink;
varapplink;
// Get the links on the page load
$(document).ready(function()
{
hostweblink = decodeURIComponent(getQueryStringParameter(“SPHostUrl”));
applink = decodeURIComponent(getQueryStringParameter(“SPAppWebUrl”));
//Add the click event
$(“#groupclick”).click(function(event)
{
groupdetails();
event.preventDefault();
});
varscriptlink = hostweblink + “/_layouts/15/”;
$.getScript(scriptlink + “SP.RequestExecutor.js”);
});
functiongetQueryStringParameter(paramToRetrieve)
{
varparamsval = document.URL.split(“?”)[1].split(“&”);
for (vari = 0; i < paramsval.length; i = i + 1)
{
var param1 = paramsval[i].split(“=”);
if (param1[0] == paramToRetrieve) return param1[1];
}
}
// Get the group content
functiongroupdetails()
{
vargrouptextval = document.getElementById(“grouptextbox”).value;
var play;
// Initialize execution
play = new SP.RequestExecutor(applink);
play.executeAsync(
{
url: applink + “/_api/SP.AppContextSite(@target)/web/sitegroups/getbyname(‘” + grouptextval + “‘)?@target='” + hostweblink + “‘”,
method: “GET”,
headers:
{
“Accept”: “application/json; odata=verbose”
},
success: groupexecutedsuccess,
error: groupexecutedfailure
});
}
// Group Executed Completed
functiongroupexecutedsuccess(data)
{
varjsonObjectval = JSON.parse(data.body);
varpropertiesval = ‘Group Properties:\n’;
propertiesval += “Title : “ + jsonObjectval.d.Title + ‘\n’;
propertiesval += “Description : “ + jsonObjectval.d.Description + ‘\n’;
propertiesval += “LoginName : “ + jsonObjectval.d.LoginName + ‘\n’;
propertiesval += “OwnerTitle : “ + jsonObjectval.d.OwnerTitle + ‘\n’;
alert(propertiesval);
}
// Group Executed Failed
functiongroupexecutedfailure(data, errorCode, errorMessage)
{
alert(“Error loading properties: “ + errorMessage);
}
Click on the settings icon on the tool on the left.
Under the properties, select **Permissions **and provide full control to the app on the Site Collection level.
Click on the deploy button on the left and run the project.
Click on the launch button.
Accept the trust and click on ‘Trust It’.
Your app will be deployed and open for you as per the following screenshot:
Provide the name of the group whom you want to check the properties.
Click on ‘Check Group Properties’ and you will find all the details as per screen below of your group.
Here we saw today how to check Group Properties using REST API in SharePoint Online and Office 365. You will love your app. Keep reading and keep learning!