SharePoint REST API for Recycle Bin

Daniele Zorzi 21 Reputation points
2021-04-13T16:02:30.74+00:00

Hi

I've got a problem with the REST API that admit to restore deleted items from SharePoint online:

_api/web/recyclebin('<recycle bin item id>')/restore()

My problem is in the specific case where after the deletion of the file and before of the restoration, someone put a file with the same name in the place where the old file was.
In this situation the HTTP request for the restoration of the file goes in "BadRequest".

If I try to perform this same operation but in the standard way (go in the recycle bin manually and restore the file) the file will be correctly restored with the name changed in <file name>(1).<extension>

Why the REST API does not perform the same operation but instead it totally fails?

Thanks

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,682 questions
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,016 Reputation points
    2021-04-14T07:37:12.857+00:00

    Hi @Daniele Zorzi ,

    Per my test, If we try to restore the deleted file in the standard way (go in the recycle bin manually and restore the file). SharePoint would rename the exsiting file (the new file somone put in the library) instead of the deleted file. Then restore it.

    When using the rest api to restore the file, you would get the error: "A file with this name <filname> already exists in <folder>. To restore the file, rename the existing file and try again."

    87614-image.png

    So, if we are using REST API to restore deleted files, you have to check and rename the existing file(new file) first, then restore it.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful