cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I get folder metadata using its ID?

How can I get folder metadata using its ID?

aleksey_novikov_kg
Explorer | Level 3

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 1

Greg-DB
Dropbox Staff

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
#   }
# }

 

 

 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?