Forum Discussion

Richard T. S.'s avatar
Richard T. S.
New member | Level 2
11 years ago

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
  • Sún B.'s avatar
    Sún B.
    New member | Level 1
    10 years ago

    Hi everyone,

    I was searching for a way to use Dropbox API to restore my files and Google brought me here.

    First of all, a bit about my situation:

    My computer got a virus that rename all of my files (idk if its recognized as rename or delete on Dropbox) and they are all synced to Dropbox. I want to download all my original files using Dropbox API.

    As i can see on web interface, I can download them individually but I got like thousand files so I couldn't do it.

    My problem:

    I used Python API wrapper to work with Dropbox API. I first fetched all of my files and tried to get all of their revisions but the original files are not included in revision list.

    Then I tried to list all of my files including deleted files and I can see my original files listed. I tried to download them using download endpoint but it returned `File not found` error. Has anyone bumped into something similar? How can I solve this issue?

    My code snippet:

    dbx = dropbox.Dropbox('token is intentionally hidden')
    print dbx.users_get_current_account()
    for entry in dbx.files_list_folder('', recursive = False, include_deleted = True).entries:
      if (isinstance(entry, dropbox.files.FileMetadata) or isinstance(entry, dropbox.files.DeletedMetadata)):
        if not entry.name.endswith('cerber2'):
          print "name: ", entry.name, "| path: ", entry.path_lower 
          print repr(entry)
          meta = dbx.files_restore(entry.path_lower)
          print repr(meta)
          try:
            meta, resp = dbx.files_download(entry.path_lower)
          except dropbox.exceptions.ApiError as e:
            print e.user_message_text
          print "-" * 80

About Dropbox API Support & Feedback

Node avatar for 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!