Syntax
REST API Endpoint:
https://SharePointSiteURL/_api/web/rootfolder?$select=WelcomePage
REST API endpoint to use in Add-ins:
<appweburl>/_api/SP.AppContextSite(@target)/web/rootfolder?$select=WelcomePage&@target=<hostweburl>
Embed Code Snippet
The following code snippet can be added to a SharePoint page or in content editor web part as a script. This example is used to retrieve the web relative URL of the Welcome Page of the SharePoint site.
- <script type="text/javascript" src="/SiteAssets/Scripts/jquery.min.js"></script>
- <script type="text/javascript">
- $.ajax(
- {
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/rootfolder?$select=welcomepage", //THE ENDPOINT
- method: "GET",
- headers:
- {
- "Accept": "application/json; odata=verbose"
- },
- success: function(data)
- {
- //RESULTS HERE!!
- console.log('Welocme page URL: ' + data.d.WelcomePage)
- alert('Welcome page URL: ' + data.d.WelcomePage);
- }
- });
- </script>
Add-in Code Snippet
The following code snippet is used in SharePoint Add-in to get the welcome page url of a SharePoint site. This returns a web relative URL of a welcome page for the site.
- // 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 WelcomePage property using REST we can hit the endpoint:
- // appweburl/_api/web?select=WelcomePage&@target=hostweburl
- // The response formats the data in the JSON format.
- executor.executeAsync(
- {
- url: appweburl + "/_api/SP.AppContextSite(@target)/web/rootfolder?$select=welcomepage&@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.WelcomePage returns the web relative URL of welcome page from the SharePoint site
- console.log('Welcome page URL: ' + jsonObject.d.WelcomePage)
- alert('Welcome page URL: ' + jsonObject.d.WelcomePage);
- }
- function errorHandler(data, errorCode, errorMessage)
- {
- console.log("Could not complete cross-domain call: " + errorMessage);
- }

Cibun SwainPosted Feb 7, 2018, 5:39 AM
"_api/web/rootfolder?$select=welcomepage " API fails for user with Read only permission. Any other way to get the welcome page for Readonly user with ResT APi?