In this blog, we’ll learn how to identify if the recyclebin is enabled or disabled in the SharePoint site using REST API
Syntax
REST API Endpoint:
https://SharePointSiteURL/_api/web?$select=RecycleBinEnabled
REST API endpoint to use in Add_ins:
<appweburl>/_api/SP.AppContextSite(@target)/web?$select= RecycleBinEnabled&@target=<hostweburl>
The following code snippet can be embed in SharePoint page or in content editor web part as a script. This example used to check whether the recyclebin 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=recyclebinenabled",
- method: "GET",
- headers:
- {
- "Accept": "application/json; odata=verbose"
- },
- success: function(data)
- {
-
- console.log(data.d.RecycleBinEnabled)
- if (data.d.TreeViewEnabled)
- alert('Recyclebin enabled on this site.');
- else
- alert('Recyclebin 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 RecycleBinEnabled 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=recyclebinenabled&@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('Tree view enabled on this site: ' + jsonObject.d.RecycleBinEnabled);
- if (jsonObject.d.RecycleBinEnabled)
- $('#message').html('Recyclebin enabled on this site.');
- else
- $('#message').html('Recyclebin disabled on this site.');
- }
-
- function errorHandler(data, errorCode, errorMessage)
- {
- console.log("Could not complete cross-domain call: " + errorMessage);
- }