Share via


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?

https://i1.wp.com/csharpcorner.mindcrackerinc.netdna-cdn.com/article/check-group-properties-using-rest-api-in-sharepoint-online-a/Images/app.jpg

 

Select SharePoint Add-in and provide a name to your app and click on Create.

https://i2.wp.com/csharpcorner.mindcrackerinc.netdna-cdn.com/article/check-group-properties-using-rest-api-in-sharepoint-online-a/Images/click%20on%20Create.jpg

You will see the screen below on the app,

https://i2.wp.com/csharpcorner.mindcrackerinc.netdna-cdn.com/article/check-group-properties-using-rest-api-in-sharepoint-online-a/Images/Content.jpg

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.

https://i2.wp.com/csharpcorner.mindcrackerinc.netdna-cdn.com/article/check-group-properties-using-rest-api-in-sharepoint-online-a/Images/settings.jpg

Under the properties, select **Permissions **and provide full control to the app on the Site Collection level.

https://i0.wp.com/csharpcorner.mindcrackerinc.netdna-cdn.com/article/check-group-properties-using-rest-api-in-sharepoint-online-a/Images/select%20Permissions.jpg

Click on the deploy button on the left and run the project.

https://i2.wp.com/csharpcorner.mindcrackerinc.netdna-cdn.com/article/check-group-properties-using-rest-api-in-sharepoint-online-a/Images/run%20the%20project.jpg

Click on the launch button.

https://i0.wp.com/csharpcorner.mindcrackerinc.netdna-cdn.com/article/check-group-properties-using-rest-api-in-sharepoint-online-a/Images/Click%20on%20the%20launch%20button.jpg

Accept the trust and click on ‘Trust It’.

https://i0.wp.com/csharpcorner.mindcrackerinc.netdna-cdn.com/article/check-group-properties-using-rest-api-in-sharepoint-online-a/Images/Trust%20It.jpg

Your app will be deployed and open for you as per the following screenshot:

https://i0.wp.com/csharpcorner.mindcrackerinc.netdna-cdn.com/article/check-group-properties-using-rest-api-in-sharepoint-online-a/Images/view%20group.jpg

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.

https://i0.wp.com/csharpcorner.mindcrackerinc.netdna-cdn.com/article/check-group-properties-using-rest-api-in-sharepoint-online-a/Images/run.jpg

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!