How to get the revision of an item with Dropbox API

1.2k views Asked by At

I am currently using the Dropbox API to get details about files. So I need show the user the file version number. However, the rev item will return a file version which is like "35c1f029684fe". This is not consistent with the Dropbox UI which shows Version 1 or Version 0. How can I get this version number?

2

There are 2 answers

4
ashes999 On BEST ANSWER

Having browsed through their file/folder metadata, I don't see any field that gives the number you want. Instead, you can use the revisions API.

https://api.dropbox.com/1/revisions/<root>/<path>

This returns something like:

[
    {
        "is_deleted": true,
        "revision": 4,
        "rev": "40000000d",
        "thumb_exists": false,
        "bytes": 0,
        "modified": "Wed, 20 Jul 2011 22:41:09 +0000",
        "path": "/hi2",
        "is_dir": false,
        "icon": "page_white",
        "root": "app_folder",
        "mime_type": "application/octet-stream",
        "size": "0 bytes"
    },
    {
        "revision": 1,
        "rev": "10000000d",
        "thumb_exists": false,
        "bytes": 3,
        "modified": "Wed, 20 Jul 2011 22:40:43 +0000",
        "path": "/hi2",
        "is_dir": false,
        "icon": "page_white",
        "root": "app_folder",
        "mime_type": "application/octet-stream",
        "size": "3 bytes"
    }
]

Note the revision numbers. There are a couple of caveats, though; some relevant snippets from the docs (emphasis mine):

Only revisions up to thirty days old are available (or more if the Dropbox user has Packrat). [...] rev_limit Default is 10. Max is 1,000. Up to this number of recent revisions will be returned.

It seems like the default parameters will return you the most recent revisions first. You can verify if this is the case; if so, it should meet your needs nicely.

0
Marcel Ribas On

Just to help people like me that Googled it and fell here. Dropbox has a new version of the API (v2) for a couple of years now. The new endpoint for versions is: https://api.dropboxapi.com/2/files/list_revisions

In the body of the request you specify the path and the limit.

The lifetime for revisions today is 30 days for Plus accounts and 180 days for Professional and Business accounts.