Automate SharePoint File Restorations with Power Automate

Accidentally deleting files in SharePoint is a common occurrence, but it doesn't have to lead to data loss or significant downtime. While the built-in Recycle Bin is a good first line of defense, organizations can further enhance their data protection strategy by automating the restoration process. By combining the power of SharePoint APIs with Power Automate, you can create robust workflows that minimize risk and ensure business continuity.

Understanding the SharePoint Recycle Bin

When a file is deleted from a SharePoint document library, it isn't immediately gone forever. It's first moved to the first-stage Recycle Bin. If a user deletes it again from there, it moves to the second-stage Recycle Bin, which is typically accessible only to site collection administrators. Microsoft 365 retains these deleted items for up to 93 days before they are permanently removed. This retention period is crucial for recovery efforts.

Can Power Automate Restore Deleted Files?

Yes, absolutely. Power Automate is capable of interacting with the SharePoint Recycle Bin through its REST APIs. By using the 'Send an HTTP request to SharePoint' action, you can programmatically retrieve information about deleted files and trigger their restoration. The key is to obtain the unique Recycle Bin ID of the file you wish to restore and then call the appropriate restore endpoint.

Solution Architecture: Automating File Restoration

Implementing an automated file restoration process with Power Automate involves several key steps:

Step 1: Trigger the Flow

The automation can be initiated in various ways, depending on your specific needs:

Step 2: Retrieve Recycle Bin Items

Once triggered, the flow needs to query the Recycle Bin. This is achieved using an HTTP request to the following SharePoint API endpoint:

GET /_api/web/RecycleBin

This action retrieves a list of all deleted files and folders currently available for recovery within the specified scope.

Step 3: Filter the Target File

The Recycle Bin can contain many items. To ensure you restore the correct file, you'll need to filter the results. You can use various criteria, such as:

By applying these filters, you can precisely identify the specific Recycle Bin item that needs to be restored.

Step 4: Restore the File

With the correct Recycle Bin item identified (using its unique ID), you can now initiate the restoration. This requires another HTTP request to one of the following endpoints:

POST /_api/web/RecycleBin('')/restore()

or

POST /_api/site/RecycleBin('')/restore()

Power Automate will execute this request, and SharePoint will restore the file to its original location.

Example Scenario: Automated Project Document Recovery

Imagine a scenario where a user accidentally deletes a critical project document. Here's how an automated flow could handle it:

  1. A scheduled flow runs every hour.
  2. It queries the SharePoint Recycle Bin for recently deleted items.
  3. It searches for files matching a specific naming pattern (e.g., "Project_Proposal_").
  4. Upon finding a match, it automatically restores the file using the API calls described above.
  5. The flow then sends a notification (via Teams or Email) to the project manager or an administrator, confirming the file has been restored.

The result? Reduced manual effort, faster recovery of critical data, and improved business continuity, all without requiring immediate IT intervention.

Real-World Use Cases

The application of automated SharePoint file restoration extends across various departments:

Best Practices for Implementation

To ensure a robust and secure automated restoration process, consider these best practices:

Benefits of Automated Restoration

Implementing this automation offers significant advantages:

Conclusion

Power Automate, when combined with SharePoint REST APIs, provides a powerful and reliable method for automating the restoration of deleted files. By leveraging the Recycle Bin endpoints and building intelligent, automated workflows, organizations can significantly improve their data protection strategies, reduce critical recovery times, and ensure seamless business continuity in the face of accidental data loss.