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

Ketak BhalsingPosted May 26, 2016, 2:08 AM
Nice Info..
Gowtham RajamanickamPosted May 25, 2016, 1:18 AM
Good one..
Debasis SahaPosted May 24, 2016, 3:00 PM
Nice Sharing..