We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
rk90
7 years agoHelpful | Level 5
How do I get all files and folders on Dropbox Business account
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 l...
Greg-DB
Dropbox Community Moderator
7 years agothere 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
7 years agoHelpful | 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-DB7 years ago
Dropbox Community Moderator
Can you share a bit of sample code/output for that case so I can take a look? Thanks in advance!
- rk907 years agoHelpful | 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-DB7 years ago
Dropbox Community Moderator
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.
About 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!