Syntax
REST API Endpoint:
https://SharePointSiteURL/_api/web?$select=NoCrawl
REST API endpoint to use in Add-ins:
<appweburl>/_api/SP.AppContextSite(@target)/web?$select= NoCrawl&@target=<hostweburl>
Embed Code Snippet
The following code snippet can be embeded in SharePoint page or in content editor web part as a script. This example is used to check whether the search is enabled for the SharePoint website.
- <script type="text/javascript" src="/SiteAssets/Scripts/jquery.min.js"></script>
- <script type="text/javascript">
- $.ajax(
- {
- url: _spPageContextInfo.webAbsoluteUrl + "/_api/web?$select=nocrawl",
- method: "GET",
- headers:
- {
- "Accept": "application/json; odata=verbose"
- },
- success: function(data)
- {
-
- console.log(data.d.NoCrawl)
- if (!data.d.NoCrawl)
- alert('Search enabled on this site.');
- else
- alert('Search disabled on this site.');
- }
- });
- </script>
Add-in Code Snippet
The following code snippet is used in SharePoint Add-in to get the boolean property of NoCrawl for the SharePoint website.
-
- $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);
-
-
- function execCrossDomainRequest()
- {
-
- var executor = new SP.RequestExecutor(appweburl);
-
-
-
-
- executor.executeAsync(
- {
- url: appweburl + "/_api/SP.AppContextSite(@target)/web?$select=nocrawl&@target='" + hostweburl + "'",
- method: "GET",
- headers:
- {
- "Accept": "application/json; odata=verbose"
- },
- success: successHandler,
- error: errorHandler
- });
- }
-
- function successHandler(data)
- {
- var jsonObject = JSON.parse(data.body)
-
- console.log('Search disabled on this site: ' + jsonObject.d.NoCrawl);
- if (!jsonObject.d.NoCrawl)
- $('#message').html('Search enabled on this site.');
- else
- $('#message').html('Search disabled on this site.');
- }
-
- function errorHandler(data, errorCode, errorMessage)
- {
- console.log("Could not complete cross-domain call: " + errorMessage);
- }