question

DanieleZorzi-7049 avatar image
0 Votes"
DanieleZorzi-7049 asked DanieleZorzi-7049 commented

SharePoint REST API for Recycle Bin

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

office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered DanieleZorzi-7049 commented

Hi @DanieleZorzi-7049,

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.






image.png (34.6 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I didn't notice that was the newer file that was renamed. Thanks

I think that this could be the correct workaround for this issue but anyway I think that this REST API should have done this by default, right?

Thanks anyway

0 Votes 0 ·