logo
search
Deleted File Recovery

How to Retrieve All SharePoint Recycle Bin Items with Python

WPS EditorWPS Editor Sep 28, 2026 869 views

Question details

The user wants to fetch every item currently in the SharePoint Online recycle bin via a Python script, which includes files that were deleted by other users.

How to Retrieve All SharePoint Recycle Bin Items Using Python
Product
SharePoint Online, Python
Device & OS
not provided
Scenario
Automating the recovery, auditing, or management of deleted SharePoint files using programming languages and APIs.
Observed behavior
Basic Python libraries like SharePy often fail to retrieve the entire recycle bin because accessing items deleted by other users requires advanced SharePoint development APIs and specific administrative permissions.
Before you start

Ensure your account or registered application possesses Site Collection Administrator privileges, as standard permissions cannot retrieve SharePoint recycle bin items deleted by other users.

Solution 1Recommended

Utilize the SharePoint REST API with Elevated Credentials

Standard SharePy operations may be limited to the current user's scope. Querying the SharePoint REST API directly with administrative credentials allows you to fetch the entire recycle bin.

To successfully retrieve items deleted by other users, your Python script must move beyond basic SharePy file operations and directly interact with SharePoint's backend development APIs. This requires constructing proper HTTP headers and handling OAuth or cookie-based authentication with Site Collection Admin rights.

1
Authenticate as a Site Administrator

Configure your Python script to authenticate using an Azure AD App Registration (MSAL) or an admin credential pipeline that grants full Site Collection Administrator access.

2
Query the Recycle Bin Endpoint

Use the Python 'requests' library to send a GET request to the SharePoint REST API endpoint: https://{your-tenant}.sharepoint.com/sites/{your-site}/_api/web/recyclebin.

3
Parse the JSON Response

Extract the returned JSON payload to view the metadata of all deleted items. Implement a loop to handle pagination if the recycle bin contains a high volume of files.

Utilize the SharePoint REST API with Elevated Credentials
API Throttling Limits: Be mindful of SharePoint Online API rate limits. If you are retrieving thousands of recycle bin items, implement backoff-and-retry logic in your Python script to avoid being blocked.
Free Microsoft Office alternative

Simplify Your Daily Document Workflow with WPS Office

While automating SharePoint API recovery requires complex programming and elevated permissions, your daily document creation shouldn't be a hassle. WPS Office provides a lightweight, highly compatible alternative to Microsoft Office for all your offline and cloud file editing needs.

  1. 1. Download the Software: Visit the official WPS Office website and click the free download button for your operating system.
  2. 2. Install the Suite: Run the downloaded installer file and follow the straightforward on-screen instructions to set up the software.
  3. 3. Edit Your Documents: Launch WPS Office to easily open, edit, and save your existing Microsoft Office files without any formatting loss.
Fully compatible with Microsoft Word, Excel, and PowerPoint file formats downloaded from SharePoint.Built-in cloud storage integration, reducing the risk of accidental data loss and complex API recoveries.Lightweight application that runs efficiently without demanding heavy system resources.Free to use with a familiar, easy-to-navigate interface for instant productivity.
microsoft office alternative - wps office

Frequently Asked Questions

Why can I only see my own deleted items in the SharePoint recycle bin via API?

By default, standard users only have permission to view and recover files they deleted themselves. To view or fetch items deleted by other users, your account or application must have Site Collection Administrator rights.

Can I use basic SharePy to access the Second-Stage Recycle Bin?

SharePy is primarily designed for handling authentication and simple file operations. Accessing the Second-Stage (Site Collection) Recycle Bin typically requires directly querying the SharePoint REST APIs or Microsoft Graph using elevated permissions.

What information is required when asking for SharePoint API troubleshooting help online?

When posting in communities like Microsoft Q&A, always include your Python code snippet, the authentication library used (e.g., SharePy or MSAL), the exact API endpoint you are calling, your permission scopes, and the specific error message received.