How to Get Root Web Information Using REST API

This article explains how to get the Root website properties using the REST API.

The following REST API URL represents the Site Collection object that can retrieve the properties based on the given SharePoint Site URL.

http://sharepointsite/_api/site

The preceding REST API URL consists of site collection properties. From the collection of all properties, we need to use the “RootWeb” property to retrieve the top-level website properties.

Syntax

http://sharepointsite/_api/site/rootweb

The preceding SharePoint REST URL returns the following properties of the root website,

Property Type Value
AllowRssFeeds Boolean TRUE
AppInstanceId Guid 00000000-0000-0000-0000-000000000000
Configuration Int16 0
Created DateTime 2015-03-16T12:06:54
CustomMasterUrl string /_catalogs/masterpage/seattle.master
Description string  
DocumentLibraryCalloutOfficeWebAppPreviewersDisabled Boolean FALSE
EnableMinimalDownload Boolean FALSE
Id Guid c3aaa420-ae4b-4355-b5e2-2b27516f2fec
Language Int32 1033
LastItemModifiedDate DateTime 2015-04-23T09:56:00Z
MasterUrl string /_catalogs/masterpage/seattle.master
QuickLaunchEnabled Boolean TRUE
RecycleBinEnabled Boolean TRUE
ServerRelativeUrl string /
SyndicationEnabled Boolean TRUE
Title string  
TreeViewEnabled Boolean TRUE
UIVersion Int32 15
UIVersionConfigurationEnabled Boolean FALSE
URL string  
WebTemplate string STS

Properties

  • AllowRssFeeds

    Retrieve the Boolean value that specifies whether the web site allows RSS feeds.

  • AppInstanceId

    Retrieves the App Instance Id of the web.

  • Configuration

    Retrieves the id of the Site definition or id of the Site template, from which the web site is created.

  • Created

    Returns the web site created date with time.

  • CustomMasterUrl

    Returns the URL of the custom master page applied to the site.

  • Description

    Returns the description of the web site.

  • DocumentLibraryCalloutOfficeWebAppPreviewersDisabled

    Returns the Boolean value that specifies whether the Web App Previewer is disabled for the site.

  • EnableMinimalDownload

    Returns the Boolean value that specifies whether the minimal download option is enabled for the site.

  • Id

    Returns the ID of the site in GUID format.

  • Language

    Returns the language code that is applied to the site.

  • LastItemModifiedDate

    Returns the date of the items that was last modified in the site.

  • MasterUrl

    Returns the URL of the default master page applied to the site.

  • QuickLaunchEnabled

    Returns the Boolean value that specifies whether the quick launch is enabled for the site.

  • RecycleBinEnabled

    Returns the Boolean value that specifies whether the recyclebin is enabled for the site.

  • ServerRelativeUrl

    Returns the server relative URL of the top level site.

  • SyndicationEnabled

    Retuns the Boolean value that specifies whether the RSS feed is enabled for the site.

  • Title

    Returns the Title of the top level site.

  • TreeViewEnabled

    Returns the Boolean value that specifies whether the tree view is enabled for the site.

  • UIVersion

    Returns the UI version used for the site.

  • UIVersionConfigurationEnabled

    Returns the Boolean value that specifies whether the settings UI for visual upgrade is shown or hidden for the site.

  • Url

    Returns the absolute URL for the website.

  • WebTemplate

    Returns the name of the site definition or site template that was used to create the top level website.

Example Code

The following code requests the root web information using the REST API, with the help jQuery ajax call and displays the properties of the root in a browser console.

  1. < script type = "text/javascript" src = "/siteassets/jquery.min.js" > < /script>  
  2. <script type="text/javascript">  
  3. //jQuery ajax used to call the REST API and get the response  
  4. jQuery.ajax({  
  5. url: "  
  6. https: //sharepointsite/_api/site/rootweb",  
  7. type: "GET",  
  8. headers: {  
  9.     "accept""application/json;odata=verbose",  
  10.     "content-type""application/json;odata=verbose",  
  11.     "X-RequestDigest": $("#__REQUESTDIGEST").val()  
  12. },  
  13. success: function(data) {  
  14.     Rootwebdetails(data);  
  15. },  
  16. error: function() {  
  17.     console.log('fail');  
  18. }  
  19. });  
  20. //Rootwebdetails method used to log the results to the browser console  
  21. function Rootwebdetails(data)   
  22. {  
  23.     console.log("Allow RSS Feeds: " + data.d.AllowRssFeeds);  
  24.     console.log("AppInstanceId: " + data.d.AppInstanceId);  
  25.     console.log("Configuration: " + data.d.Configuration);  
  26.     console.log("Created: " + data.d.Created);  
  27.     console.log("CustomMasterUrl: " + data.d.CustomMasterUrl);  
  28.     console.log("Description: " + data.d.Description);  
  29.     console.log("DocumentLibraryCalloutOfficeWebAppPreviewersDisabled: " + data.d.DocumentLibraryCalloutOfficeWebAppPreviewersDisabled);  
  30.     console.log("EnableMinimalDownload: " + data.d.EnableMinimalDownload);  
  31.     console.log("Id: " + data.d.Id);  
  32.     console.log("Language: " + data.d.Language);  
  33.     console.log("LastItemModifiedDate: " + data.d.LastItemModifiedDate);  
  34.     console.log("MasterUrl: " + data.d.MasterUrl);  
  35.     console.log("QuickLaunchEnabled: " + data.d.QuickLaunchEnabled);  
  36.     console.log("RecycleBinEnabled: " + data.d.RecycleBinEnabled);  
  37.     console.log("ServerRelativeUrl: " + data.d.ServerRelativeUrl);  
  38.     console.log("SyndicationEnabled: " + data.d.SyndicationEnabled);  
  39.     console.log("Title: " + data.d.Title);  
  40.     console.log("TreeViewEnabled: " + data.d.TreeViewEnabled);  
  41.     console.log("UIVersion: " + data.d.UIVersion);  
  42.     console.log("UIVersionConfigurationEnabled: " + data.d.UIVersionConfigurationEnabled);  
  43.     console.log("Url: " + data.d.Url);  
  44.     console.log("WebTemplate: " + data.d.WebTemplate);  
  45. }   
  46. < /script>  
Summary

The root web properties can be accessed directly from the REST URL, with specification of the index number, web title or URL. These properties can be used in many ways during the creation of Apps or other root web related client-side applications.

Up Next
    Ebook Download
    View all
    Learn
    View all