top of page

Check Group Properties Using REST API In SharePoint Online And Office 365

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 PropertiesNow on the navigation click on the App.js file and paste the code below removing the previous code completely.


Code:

  1. ‘use strict’;

  2. varhostweblink;

  3. varapplink;

  4. // Get the links on the page load

  5. $(document).ready(function()

  6. {    

  7. hostweblink = decodeURIComponent(getQueryStringParameter(“SPHostUrl”));    

  8. applink = decodeURIComponent(getQueryStringParameter(“SPAppWebUrl”));

  9. //Add the click event    

  10. $(“#groupclick”).click(function(event)    

  11. {        

  12. groupdetails();

  13. event.preventDefault();    

  14. });    

  15. varscriptlink = hostweblink + “/_layouts/15/”;    

  16. $.getScript(scriptlink + “SP.RequestExecutor.js”);

  17. });

  18. functiongetQueryStringParameter(paramToRetrieve)

  19. {    

  20. varparamsval = document.URL.split(“?”)[1].split(“&”);

  21. for (var i = 0; i < paramsval. length; i = i + 1)    

  22. {        

  23. var param1 = paramsval[i].split(“=”);

  24. if (param1[0] == paramToRetrieve) return param1[1];    

  25. }}

  26. // Get the group content

  27. functiongroupdetails()

  28. {    

  29. vargrouptextval = document.getElementById(“grouptextbox”).value;    

  30. var play;

  31. // Initialize execution    

  32. play = new SP.RequestExecutor(applink);    

  33. play.executeAsync(    

  34. {        

  35. url: applink + “/_api/SP.AppContextSite(@target)/web/sitegroups/getbyname(‘” + grouptextval + “‘)?@target='” + hostweblink + “‘”,        

  36. method: “GET”,        

  37. headers:        

  38. { “Accept”: “application/json; odata=verbose”        

  39. },       

  40.  success: groupexecutedsuccess,        

  41. error: groupexecutedfailure    

  42. });

  43. }

  44. // Group Executed Completed

  45. functiongroupexecutedsuccess(data)

  46. {    

  47. varjsonObjectval = JSON.parse(data.body);   

  48.  varpropertiesval = ‘Group Properties:\n’;    

  49. propertiesval += “Title : “ + jsonObjectval.d.Title + ‘\n’;    

  50. propertiesval += “Description : “ + jsonObjectval.d.Description + ‘\n’;    

  51. propertiesval += “LoginName : “ + jsonObjectval.d.LoginName + ‘\n’;    

  52. propertiesval += “OwnerTitle : “ + jsonObjectval.d.OwnerTitle + ‘\n’;    

  53. alert(propertiesval);

  54. }

  55. // Group Executed Failed

  56. functiongroupexecutedfailure(data, errorCode, errorMessage)

  57. {    

  58. alert(“Error loading properties: “ + errorMessage);

  59. }


  • 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!

0 comments
bottom of page