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: 

Re: How do I get all files and folders on Dropbox Business account

How do I get all files and folders on Dropbox Business account

rk90
Helpful | Level 5

I have asked this question in the past and did get answers but I am still struggling to figure this out.

Basically, I want to export the entire structure of the given Dropbox Business account to a local DB. I want to export each and every folder/file to the DB.

Do I list this namespaces and use the namespace id as path to traverse each folder? Would that cover all the folders that are there? How would I de-duplicate the traversed folders? How do I segregate between Private, Shared and Team folders?

Can you recommend an approach and provide some guidance?

 

 

 

15 Replies 15

rk90
Helpful | Level 5

This is not true, there are several folders that are inside team folders and show up within the team folder on the UI, but when I list those folders via API I don't see `path_display`. Moreover, there are several deleted files/folders in the response that just have `name` but no `path_display` or `path_lower`. 

Note that if a Metadata object doesn't contain `path_lower` or `path_display`, it indicates that "the file or folder is not mounted". I.e., it's in a shared folder that isn't currently added to the account, so it doesn't have a path in the account.

I am frustrated because of the disambiguity and unnecessary optional fields in the response. Most importantly if someone was given a task to generate the list of all files/folders on a given Dropbox account, it will take them forever because Dropbox doesn't have an endpoint that can be called to list each and every folder. What Dropbox expects us to do is call `list_folder/{continue}`. Consider 1000 members that have almost identical folders (i.e. a large shared folder shared with all of them). When I list each member's folder recursively I will be unneccesarily listing that same shared folder 1000 times. If I want to skip listing that folder again, then I need to set `recursive=False` and check each folder in response to see if it was listed previously, unnecssary processing. APIs are suppossed to make life easier not difficult.

Greg-DB
Dropbox Staff

there are several folders that are inside team folders and show up within the team folder on the UI, but when I list those folders via API I don't see `path_display`

Do you mean you're calling for a namespace directly as an admin without a root like this?

 

curl -X POST https://api.dropboxapi.com/2/files/list_folder \
    --header "Authorization: Bearer <ACCESS_TOKEN>" \
    --header "Dropbox-API-Select-Admin: <ADMIN_USER_ID>" \
    --header "Content-Type: application/json" \
    --data "{\"path\": \"ns:1990893360\"}"

# {
#   "entries": [
#     {
#       ".tag": "folder",
#       "name": "test",
#       "parent_shared_folder_id": "1990893360",
#       "id": "id:hro-cp_zmJAAAAAAAAAACg",
#       "sharing_info": {
#         "read_only": false,
#         "parent_shared_folder_id": "1990893360",
#         "traverse_only": false,
#         "no_access": false
#       }
#     },
#     {
#       ".tag": "folder",
#       "name": "test folder in team folder",
#       "parent_shared_folder_id": "1990893360",
#       "id": "id:hro-cp_zmJAAAAAAAAAADw",
#       "shared_folder_id": "3980274560",
#       "sharing_info": {
#         "read_only": false,
#         "parent_shared_folder_id": "1990893360",
#         "shared_folder_id": "3980274560",
#         "traverse_only": false,
#         "no_access": false
#       }
#     }
#   ],
#   "cursor": "...",
#   "has_more": false
# }

The paths aren't returned because this call isn't rooted anywhere; i.e., there's no root for the paths to be mounted relative to.

 

Instead, you can supply the path root using the 'Dropbox-API-Path-Root' header (from the Namespace Guide), like this:

 

curl -X POST https://api.dropboxapi.com/2/files/list_folder \
    --header "Authorization: Bearer <ACCESS_TOKEN>" \
    --header "Dropbox-API-Select-Admin: <ADMIN_USER_ID>" \
    --header 'Dropbox-API-Path-Root: {".tag": "root", "root": "1990815600"}' \
    --header "Content-Type: application/json" \
    --data "{\"path\": \"ns:1990893360\"}"

# {
#   "entries": [
#     {
#       ".tag": "folder",
#       "name": "test",
#       "path_lower": "/team folder 1/test",
#       "path_display": "/team folder 1/test",
#       "parent_shared_folder_id": "1990893360",
#       "id": "id:hro-cp_zmJAAAAAAAAAACg",
#       "sharing_info": {
#         "read_only": false,
#         "parent_shared_folder_id": "1990893360",
#         "traverse_only": false,
#         "no_access": false
#       }
#     },
#     {
#       ".tag": "folder",
#       "name": "test folder in team folder",
#       "path_lower": "/team folder 1/test folder in team folder",
#       "path_display": "/team folder 1/test folder in team folder",
#       "parent_shared_folder_id": "1990893360",
#       "id": "id:hro-cp_zmJAAAAAAAAAADw",
#       "shared_folder_id": "3980274560",
#       "sharing_info": {
#         "read_only": false,
#         "parent_shared_folder_id": "1990893360",
#         "shared_folder_id": "3980274560",
#         "traverse_only": false,
#         "no_access": false
#       }
#     }
#   ],
#   "cursor": "...",
#   "has_more": false
# }

 

 

rk90
Helpful | Level 5

Yes, I am not supplying the 'with root path' header. What about the deleted files/folders? There are several that don't return the path_display.

Greg-DB
Dropbox Staff

Can you share a bit of sample code/output for that case so I can take a look? Thanks in advance! 

rk90
Helpful | Level 5
for namespace_list in session.post('2/team/namespaces/list'): 
    for namespace in namespace_list: 
        for listing in session.post('2/files/list_folder', headers={'Dropbox-API-Select-Admin': <team_member_id>}, json={'path': f'ns:{namespace[namespace_id]}', 'recursive': True, 'include_deleted': True}):
            for item in listing:
                print(item)

Above is an example of the approach I am taking to list all folders. Part of the problem is if a folder is shared with all members, then when I list 'team_member_folders' I am listing the same folder multiple times.

    

Greg-DB
Dropbox Staff

Thanks! The omission of the path on the deleted entries in this case would be for the same reason as mentioned in my previous post yesterday; i.e., without the path root there's no root for the paths to be mounted relative to.

For shared folders, the shared folder ID will be consistent across users, so you can keep a list of the IDs you've seen already, and skip them when you come across them again.

Need more support?