We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Richard T. S.
11 years agoNew member | Level 2
How to Undelete a File via the API
I tried to do a restore ... that did not seem to work.
Is undelete only available via the Web interface ?
22 Replies
Replies have been turned off for this discussion
- Steve M.11 years ago
Dropbox Staff
/restoreis the right endpoint. When you say it "did not seem to work," what do you mean? What did you try, and what exactly went wrong? - Richard T. S.11 years agoNew member | Level 2
I restored using the latest version ... is the latest version the deleted version ?
It return an error indicating the file did not exist.
Maybe I needed to use the N-1 version.
- Richard T. S.11 years agoNew member | Level 2
I was able to restore using the N-1 version. (i.e. the second revision returned from the revisions call)
Might be good to add a comment or example on restore API on how to undelete a file.
- Leah C.111 years agoNew member | Level 1
Thanks for the suggestion!
- Richard T. S.10 years agoNew member | Level 2
I can't believe this bit me again. The first time was with the Android V1 API. Now with the .NET API
The Scenario:
From the WebPage Access I delete a file.
Then from the API I detect the file does not exist (Fails on the GetMetadata request for the path.)
So I check to see if I can restore by calling ListRevisions. It shows file is deleted. I get 3 back FileMetadata entries: (Deleted, MostRecent, Orignal).
If I try yo restore the Delete file it fails ... indicating ivalid revision ... but there is NOTHING in the FileMetaData that indicates the first entry is Deleted ... i.e. should the IsDeleted flag be set ?
I tried to use Files.RestoreAsync using the Revison from all 3 FileMetadata returned from ListRevisions and was not able to restore.
- Greg-DB10 years ago
Dropbox Community Moderator
Richard, can you share some sample code/output for the issues you're seeing? Thanks in advance!
- Richard T. S.10 years agoNew member | Level 2public async Task<FileMetadata> RestoreFile(String DBPath) {FileMetadata result = null;try {ListRevisionsResult rev = await mClient.Files.ListRevisionsAsync(DBPath);if (rev.IsDeleted) {foreach (FileMetadata md in rev.Entries) {try {return await mClient.Files.RestoreAsync(DBPath, md.Rev);} catch (Exception) {PersistLog.e(TAG, String.Format("RestoreFile:Failed for:{0} revision:{1}", DBPath, md.Rev));}}}} catch (Exception) {PersistLog.e(TAG, String.Format("RestoreFile:Failed for:{0}", DBPath));}return result;}
- Greg-DB10 years ago
Dropbox Community Moderator
Can you also post whatever error or unexpected output you're getting? Thanks!
- Richard T. S.10 years agoNew member | Level 2
Inspecting information from the limited feedback in the exception ... It indicates the Revision is bad.
- Greg-DB10 years ago
Dropbox Community Moderator
Your code is working fine to restore a file in my testing. Can you share the output you're getting (what you're logging with PersistLog)? That looks like it may contain some useful information for your particular case.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!