“Can I restrict users from restoring deleted files from the recycle bin, to delete them also from there within Power Automate flow?”
If you use SharePoint as a document management system, you get a lot of functionality out of the box. Files are versioned, there’s support for draft/published versions, and nothing is deleted permanently. And that’s great in many situations. But in some specific situations it’s not beneficial, more specifically if you delete files using a flow and users keep restoring them from the recycle bin.
How do you fully delete a file to avoid it?
Delete file from a recycle bin with an HTTP request
As Power Automate doesn’t have any action related to the SharePoint recycle bin, you must use a “workaround”. That means another HTTP requests, or two…
To delete a file from a recycle bin you need the file ID. Not the file name, not the identifier, but the unique id in the recycle bin. This id will be among the outputs of the HTTP request below…
Method:
GET
Uri:
_api/web/RecycleBin?$filter=LeafName eq '<fileNameWithExtension>'&$select=Id

…and you can access it directly with this expression:
body('Send_an_HTTP_request_to_SharePoint')?['d']?['results'][0]?['Id']
Once you have the id you can do the actual removal from the recycle bin.
Method:
DELETE
Uri:
_api/web/RecycleBin('<fileUniqueId>')

That’s it, the file is completely gone.
Summary
Recycle bin is another part of SharePoint that doesn’t have a direct support from Power Automate, yet if you delete any file it’ll always end there. If you want to remove it also from the recycle bin, you’ll need two HTTP requests – one to get the file ID and another one to delete the file. Just be careful with the solution as it’s bypassing one of the safety SharePoint features. Once you delete the file it’ll be deleted completely.
Can this be wrapped in a for each to collect all the unique IDs of any files with a specific file type and then run the delete request for every file found in the recycle bin that has that file type?
Hello Benjamin,
yes, it can. In the example I’m selecting only the specific file using the index [0] as I’m expecting that it’ll return only one file since I’m searching by the full file name. But if you modify the filter to get multiple files, you can add a loop and delete all of them.