Forum Discussion

aleksey_novikov_kg's avatar
aleksey_novikov_kg
Explorer | Level 3
6 years ago

How can I get folder metadata using its ID?

I have a folder ID.

 

I've checked API Dropbox there is a `files/get_metadata` endpoint https://www.dropbox.com/developers/documentation/http/documentation#files-get_metadata

 

{
    "path": "id:a4ayc_80_OEAAAAAAAAAYa",
    "include_media_info": false,
    "include_deleted": false,
    "include_has_explicit_shared_members": false
}


This endpoint is taking path argument which could be and path, id, and rev. In my case ID is fitting perfectly, because I know ID of the created folder and storing it in DB. 

 

But I'm getting `path not found` error while trying to send ID. How can I get folder metadata using folder ID? 

 

1 Reply

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    6 years ago

    You can use the ID for a folder (or file) to retrieve the metadata for the item using /2/files/get_metadata, by passing in the 'id' string in the "path" parameter. Here's a simple example of that, first getting the metadata by path, and then by ID:

     

     

    curl -X POST https://api.dropboxapi.com/2/files/get_metadata \
        --header "Authorization: Bearer <ACCESS_TOKEN>" \
        --header "Content-Type: application/json" \
        --data "{\"path\": \"/Testing\"}"
    
    # {
    #   ".tag": "folder",
    #   "name": "Testing",
    #   "path_lower": "/testing",
    #   "path_display": "/Testing",
    #   "id": "id:25N5ksooX-sAAAAAAAAB5w"
    # }
    
    
    curl -X POST https://api.dropboxapi.com/2/files/get_metadata \
        --header "Authorization: Bearer <ACCESS_TOKEN>" \
        --header "Content-Type: application/json" \
        --data "{\"path\": \"id:25N5ksooX-sAAAAAAAAB5w\"}"
    
    # {
    #   ".tag": "folder",
    #   "name": "Testing",
    #   "path_lower": "/testing",
    #   "path_display": "/Testing",
    #   "id": "id:25N5ksooX-sAAAAAAAAB5w"
    # }

     

     

     

     

     

    There are a few reasons you may get a 'path/not_found' error when attempting to do so though. For example, the ID may be for an item that no longer exists, or you may be using an access token for an account that does not contain the item identified by the ID.

     

    Another possibility is that you're not using the right "root" for the item. The API call needs to be rooted in the correct "namespace" that contains the item in order to find it. By default, API calls are rooted in the user's own folder, so if the item isn't in the user's own folder, and is, say, in the "team space" instead, you'd need to configure the API call accordingly. I recommend reviewing the Namespace Guide for information on how that works.

     

    Here's an example of that, of where a folder is in the team space, so trying to access it by ID without specifying the team space as the root fails:

     

    curl -X POST https://api.dropboxapi.com/2/files/get_metadata \
        --header "Authorization: Bearer <ACCESS_TOKEN>" \
        --header 'Dropbox-API-Path-Root: {".tag": "root", "root": "1990815600"}' \
        --header "Content-Type: application/json" \
        --data "{\"path\": \"/some folder\"}"
    
    # {
    #   ".tag": "folder",
    #   "name": "some folder",
    #   "path_lower": "/some folder",
    #   "path_display": "/some folder",
    #   "parent_shared_folder_id": "1990815600",
    #   "id": "id:txUaMSvNXjAAAAAAAAAAAQ",
    #   "shared_folder_id": "5587390608",
    #   "sharing_info": {
    #     "read_only": false,
    #     "parent_shared_folder_id": "1990815600",
    #     "shared_folder_id": "5587390608",
    #     "traverse_only": false,
    #     "no_access": false
    #   }
    # }
    
    
    
    curl -X POST https://api.dropboxapi.com/2/files/get_metadata \
        --header "Authorization: Bearer <ACCESS_TOKEN>" \
        --header "Content-Type: application/json" \
        --data "{\"path\": \"id:txUaMSvNXjAAAAAAAAAAAQ\"}"
    
    # {
    #   "error_summary": "path/not_found/",
    #   "error": {
    #     ".tag": "path",
    #     "path": {
    #       ".tag": "not_found"
    #     }
    #   }
    # }
    
    
    
    curl -X POST https://api.dropboxapi.com/2/files/get_metadata \
        --header "Authorization: Bearer <ACCESS_TOKEN>" \
        --header 'Dropbox-API-Path-Root: {".tag": "root", "root": "1990815600"}' \
        --header "Content-Type: application/json" \
        --data "{\"path\": \"id:txUaMSvNXjAAAAAAAAAAAQ\"}"
    
    # {
    #   ".tag": "folder",
    #   "name": "some folder",
    #   "path_lower": "/some folder",
    #   "path_display": "/some folder",
    #   "parent_shared_folder_id": "1990815600",
    #   "id": "id:txUaMSvNXjAAAAAAAAAAAQ",
    #   "shared_folder_id": "5587390608",
    #   "sharing_info": {
    #     "read_only": false,
    #     "parent_shared_folder_id": "1990815600",
    #     "shared_folder_id": "5587390608",
    #     "traverse_only": false,
    #     "no_access": false
    #   }
    # }

     

     

     

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!