Identify ifRecyleBin is Enabled for SharePoint Site Using REST API

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>
 
Embed Code Snippet

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.
  1. <script type="text/javascript" src="/SiteAssets/Scripts/jquery.min.js"></script>  
  2. <script type="text/javascript">  
  3.     $.ajax(  
  4.     {  
  5.         url: _spPageContextInfo.webAbsoluteUrl + "/_api/web?$select=recyclebinenabled"//THE ENDPOINT    
  6.         method: "GET",  
  7.         headers:  
  8.         {  
  9.             "Accept""application/json; odata=verbose"  
  10.         },  
  11.         success: function(data)  
  12.         {  
  13.             //RESULTS HERE!!    
  14.             console.log(data.d.RecycleBinEnabled)  
  15.             if (data.d.TreeViewEnabled)  
  16.                 alert('Recyclebin enabled on this site.');  
  17.             else  
  18.                 alert('Recyclebin disabled on this site.');  
  19.         }  
  20.     });  
  21. </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.
  1. // Load the js files and continue to the successHandler    
  2. $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);  
  3. // Function to prepare and issue the request to get    
  4. // SharePoint data    
  5. function execCrossDomainRequest()  
  6. {  
  7.     // Initialize the RequestExecutor with the add-in web URL.    
  8.     var executor = new SP.RequestExecutor(appweburl);  
  9.     // Issue the call against the add-in web.    
  10.     // To get the RecycleBinEnabled property using REST we can hit the endpoint:    
  11.     // appweburl/_api/web?select=RecycleBinEnabled&@target=hostweburl    
  12.     // The response formats the data in the JSON format.    
  13.     executor.executeAsync(  
  14.     {  
  15.         url: appweburl + "/_api/SP.AppContextSite(@target)/web?$select=recyclebinenabled&@target='" + hostweburl + "'",  
  16.         method: "GET",  
  17.         headers:  
  18.         {  
  19.             "Accept""application/json; odata=verbose"  
  20.         },  
  21.         success: successHandler,  
  22.         error: errorHandler  
  23.     });  
  24. }  
  25. // Function to handle the success event.    
  26. function successHandler(data)  
  27. {  
  28.     var jsonObject = JSON.parse(data.body)  
  29.         //jsonObject.d.TreeViewEnabled returns true if enabled otherwise it returns false    
  30.     console.log('Tree view enabled on this site: ' + jsonObject.d.RecycleBinEnabled);  
  31.     if (jsonObject.d.RecycleBinEnabled)  
  32.         $('#message').html('Recyclebin enabled on this site.');  
  33.     else  
  34.         $('#message').html('Recyclebin disabled on this site.');  
  35. }  
  36.   
  37. function errorHandler(data, errorCode, errorMessage)  
  38. {  
  39.     console.log("Could not complete cross-domain call: " + errorMessage);  
  40. }