Forum Discussion

TEK P.'s avatar
TEK P.
New member | Level 1
10 years ago

Find the last updated timestamp of a directory (that includes changes to any of the files in the directory - add/modify/delete)

Challenge: Use Dropbox REST API to get the last updated timestamp of a directory (that includes changes to any of the files in the directory - add/modify/delete).

1) I tried using the API v1 first:

    curl -XPOST https://api.dropbox.com/1/delta -H "Authorization:Bearer ********AuthorizationKey*********" --data "path_prefix=/toratoratora/reports"

    {"has_more": true, "cursor": "**********CURSOR**********", "entries": [["/toratoratora/reports", {"rev": "7e3633bc43", "thumb_exists": false, "path": "/toratoratora/reports", "is_dir": true, "icon": "folder_user", "read_only": false, "modifier": null, "bytes": 0, "modified": "Tue, 22 Dec 2015 23:43:54 +0000", "shared_folder": {"shared_folder_id": "1099510378", "is_team_only_shared_folder": false}, "size": "0 bytes", "root": "dropbox", "revision": 126}]], "reset": true}

However, the timestamp returned above is NOT the last time a file in the directory was modified (add/modify/delete).

2) So, I tried using the API v2:


    curl -X POST https://api.dropboxapi.com/2/files/get_metadata \
        --header "Authorization: Bearer ********AuthorizationKey*********" \
        --header "Content-Type: application/json" \
        --data "{\"path\": \"/toratoratora/reports/file_name.xlsx\",\"include_media_info\": true}"

    {".tag": "folder", "name": "Reports", "path_lower": "/toratoratora/reports", "id": "id:******ID******", "shared_folder_id": "dbsfid:###dbsfid####", "sharing_info": {"read_only": false, "shared_folder_id": "dbsfid:****dbsfid****"}}

Although I've specified "include_media_info" as TRUE, the timestamp values for "client_modified" & "server_modified" are NOT included in the result as the request is for a directory and NOT a file.


3) No luck when I usedget_metada:

    curl -X POST https://api.dropboxapi.com/2/files/get_metadata --header "Authorization: Bearer ********AuthorizationKey*********" --header "Content-Type: application/json" --data "{\"path\": \"/toratoratora/reports\", \"include_media_info\": true}"

    {".tag": "folder", "name": "Reports", "path_lower": "/toratoratora/reports", "id": "id:******ID******", "shared_folder_id": "dbsfid:###dbsfid####", "sharing_info": {"read_only": false, "shared_folder_id": "dbsfid:****dbsfid****"}}


4) One thing that looks promising is "list_folder"

    curl -X POST https://api.dropboxapi.com/2/files/list_folder \
        --header "Authorization: Bearer ********AuthorizationKey*********" \
        --header "Content-Type: application/json" \
        --data "{\"path\": \"/toratoratora/reports\",\"recursive\": false,\"include_media_info\": true,\"include_deleted\": true}"

This lists all the individual files and their timestamps. However, since the timestamps are NOT returned for DELETED files, there's NO way to find when the file was deleted & hence the directory was last updated.

Does anybody have a solution for this problem?

Do the Python API (https://www.dropbox.com/developers/documentation/python) have better options?

1 Reply

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    [Cross-linking for reference: https://stackoverflow.com/questions/35072308/dropbox-api-find-the-last-updated-timestamp-of-a-directory-that-includes-chang ]

    The API (v1 or v2) doesn't currently return a modified time for folders that reflects changes inside that folder. I'll send this along as a feature request though.

     

    For reference "include_media_info" on /files/get_metadata is documented as:

    "If true, FileMetadata.media_info is set for photo and video. The default for this field is False."

    That being the case, that parameter shouldn't have any impact on client_modified or server_modified.

     

    I'll also send along a feature request to include timestamps for deleted files.

     

    Finally, the Python SDK uses the same API you've been testing with, so there won't be any difference there.

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!