Syntax:
REST API Endpoint:
https://SharePointSiteURL/_api/web/parentweb?$select=Title
https://SharePointSiteURL/_api/web/parentweb?$select=Title
REST API endpoint to use in Add-ins:
<appweburl>/_api/SP.AppContextSite(@target)/web/parentweb?$select=Title&@target=<hostweburl>
Embed Code Snippet
The following code snippet can be added to a SharePoint page or in the content editor web part as a script. This example used to retrieve the parent website of the current site and its title property. If you are in a top-level site, the REST url returns the empty information.
- <script type="text/javascript" src="/SiteAssets/Scripts/jquery.min.js"></script>
- <script type="text/javascript">
- $.ajax(
- {
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/parentweb", //THE ENDPOINT
- method: "GET",
- headers:
- {
- "Accept": "application/json; odata=verbose"
- },
- success: function(data)
- {
- //RESULTS HERE!!
- console.log('Parent site title: ' + data.d.Title)
- alert('Parent site title: ' + data.d.Title);
- }
- });
- </script>
Add-in Code Snippet
The following code snippet is used in SharePoint Add-in to retrieve the parent website information and displays the parent website title.
- // Load the js files and continue to the successHandler
- $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);
- // Function to prepare and issue the request to get
- // SharePoint data
- function execCrossDomainRequest()
- {
- // Initialize the RequestExecutor with the add-in web URL.
- var executor = new SP.RequestExecutor(appweburl);
- // Issue the call against the add-in web.
- // To get the parentweb object using REST we can hit the endpoint:
- // appweburl/_api/web/parentweb?@target=hostweburl
- // The response formats the data in the JSON format.
- executor.executeAsync(
- {
- url: appweburl + "/_api/SP.AppContextSite(@target)/web/parentweb?@target='" + hostweburl + "'",
- method: "GET",
- headers:
- {
- "Accept": "application/json; odata=verbose"
- },
- success: successHandler,
- error: errorHandler
- });
- }
- // Function to handle the success event.
- function successHandler(data)
- {
- var jsonObject = JSON.parse(data.body)
- //jsonObject.d.Title returns the title of parent website
- console.log('Parent website title: ' + jsonObject.d.Title)
- alert('Parent website title: ' + jsonObject.d.Title);
- }
- function errorHandler(data, errorCode, errorMessage)
- {
- console.log("Could not complete cross-domain call: " + errorMessage);
- }

Join the conversation! Your thoughts help the community grow.