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

Welcome to an article on “How to Check Site Properties using REST API in SharePoint Online and Office 365” where we will see the steps of checking the site 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?

    app

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

    click on Create

  • You will see the screen below on the app,

    Content

    Click on Default.aspx and paste the code below under the “<asp:ContentContentPlaceHolderID="PlaceHolderMain" runat="server">”.

    Code:
    1. <div>  
    2.    <p>  
    3.       <br />  
    4.       <button id="getsiteproperties">Get all site properties</button>  
    5.    </p>  
    6. </div>  

  • Now on the navigation click on the App.js file and paste the code below removing the previous code completely.

    Code:
    1. 'use strict';  
    2. var hostweblink;  
    3. var applink;  
    4. // Get the links on the app load  
    5. $(document).ready(function()  
    6. {  
    7.     hostweblink = decodeURIComponent(getQueryStringval("SPHostUrl"));  
    8.     applink = decodeURIComponent(getQueryStringval("SPAppWebUrl"));  
    9.     //click function  
    10.     $("#getsiteproperties").click(function(event)  
    11.     {  
    12.         getsiteProperties();  
    13.         event.preventDefault();  
    14.     });  
    15.     var scriptlink = hostweblink + "/_layouts/15/"  
    16.     $.getScript(scriptlink + "SP.RequestExecutor.js");  
    17. });  
    18.   
    19. function getQueryStringval(paramToRetrieve)  
    20. {  
    21.     var paramval = document.URL.split("?")[1].split("&");  
    22.     for (var i = 0; i < paramval.length; i = i + 1)  
    23.     {  
    24.         var paramval1 = paramval[i].split("=");  
    25.         if (paramval1[0] == paramToRetrieve) return paramval1[1];  
    26.     }  
    27. }  
    28. // Get the site properties  
    29. function getsiteProperties()  
    30. {  
    31.     var play;  
    32.     play = new SP.RequestExecutor(applink);  
    33.     play.executeAsync(  
    34.     {  
    35.         url: applink + "/_api/SP.AppContextSite(@target)/web?@target='" + hostweblink + "'",  
    36.         method: "GET",  
    37.         headers:  
    38.         {  
    39.             "Accept""application/json; odata=verbose"  
    40.         },  
    41.         success: getsitePropertiespassed,  
    42.         error: getsitePropertiesfailed  
    43.     });  
    44. }  
    45. // If the function is valid  
    46. function getsitePropertiespassed(data)  
    47. {  
    48.     var jsonObjval = JSON.parse(data.body);  
    49.     var siteproperties = 'Web Properties:\n';  
    50.     siteproperties += "Title : " + jsonObjval.d.Title + '\n';  
    51.     siteproperties += "URL : " + jsonObjval.d.Url + '\n';  
    52.     alert(siteproperties);  
    53. }  
    54. // If the function is invalid  
    55. function getsitePropertiesfailed(data, errorCode, errorMessage)  
    56. {  
    57.     alert("The following error prevents to load the site properties: " + errorMessage);  
    58. }  

  • Click on the settings icon on the tool on the left.

    Setting

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

    Permission

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

    Run project

  • Click on the launch button.

    Lunch app

  • Accept the trust and click on ‘Trust It’.

    Trust It

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

    Get all site properties

  • Click on ‘Get all site properties’ and you will find all the details as per screen below of your group.

    Clich ok

You will see the title of the site and the web Url of your application which you can use for extending your app functionality.

Here we saw today How to Check Site Properties using REST API in SharePoint Online and Office 365. You will love your app. Keep reading and keep learning!

Read more articles on SharePoint: