cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right here.

Discuss Dropbox Developer & API

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

Listing team folders and content

Listing team folders and content

biswas_nu
New member | Level 2
 
I need a critical help with question below. i am developing a backup and restore solution which backups data from dropbox and store in s3 bucket. I am using typescript lambda to achieve the same

Now I have been so far successful listing the users in a dropbiox business account and listing their files and folders successfully

Some snippets of code related to it are

  1. List users: https://api.dropboxapi.com/2/team/members/list_v2
  2. Fetch team_member_id for these users
  3. Create dropbox client using
         const dbx: any = new Dropbox({
                           accessToken: access_token,
                           fetch: fetch,
                           selectUser: team_member_id
                       });
  1. Recursively call below to get all files and folders for that particular team member. Please note the access token is obtained using oauth flow using admin account
        if (cursor === "") {
            result = await retry(() => dbx.filesListFolder({ path: "", recursive: true }));
        } else {
            result = await retry(() => dbx.filesListFolderContinue({ cursor }));
        }

Now I need to list all the team folders and its content too along with user specific content For it I tried

  1. Getting list of team folders using : const teamFolderUrl = 'https://api.dropboxapi.com/2/team/team_folder/list';
  2. Get the team_folder_id
  3. Create dropbox client using
         const dbx: any = new Dropbox({
                           accessToken: access_token,
                           fetch: fetch,
                       });
  1. Recursively call below to get all files and folders for that particular team member. Please note the access token is obtained using oauth flow using admin account
        if (cursor === "") {
            result = await retry(() => dbx.filesListFolder({ path: "/team_folder", recursive: true }));
        } else {
            result = await retry(() => dbx.filesListFolderContinue({ cursor }));
        }

but I am getting error

  error: `Error in call to API function "files/list_folder": This API function operates on a single Dropbox account, but the OAuth 2 access token you provided is for an entire Dropbox Business team.  Since your API app key has team member file access permissions, you can operate on a team member's Dropbox by providing the "Dropbox-API-Select-User" HTTP header or "select_user" URL parameter to specify the exact user <https://www.dropbox.com/developers/documentation/http/teams>.`

require your help in detailed understanding of the issue

10 Replies 10

Здравко
Legendary | Level 20

@biswas_nu wrote:

...

require your help in detailed understanding of the issue


Hi @biswas_nu,

Your issue is that tokens don't impersonate anybody personally when they authenticate a team. File access of any type require user/member to be acting though (the team on its own cannot be acting side)! That's why you need to add member information while working on team account files with team tokens as noted in the error message. One thing that is missing in the error message is that you can make team folder content list as admin too, not only as user having access to there (i.e. you may and have to use either selectAdmin or selectUser option).

Hope this helps.

biswas_nu
New member | Level 2

This value comes however in case of user file

 

2024-09-13T12:33:46.823Z 7b23231c-d109-59e2-9a4e-7c42e2455f91 INFO Entry for normal file: {
'.tag': 'file',
name: 'IMG_2234.MOV',
path_lower: '/cloudportal_restore_05c52d00-701f-11ef-ae02-55ed4bd144bc/photos and videos/saaher iphone 5s/965yokdj/img_2234.mov',
path_display: '/CloudPortal_Restore_05c52d00-701f-11ef-ae02-55ed4bd144bc/Photos and Videos/Saaher iphone 5s/965YOKDJ/IMG_2234.MOV',
id: 'id:bIDhMLTvgPsAAAAAAAAVzw',
client_modified: '2024-09-11T09:23:21Z',
server_modified: '2024-09-11T09:23:22Z',
rev: '01621d48a95676d00000001314ef691',
size: 26728433,
is_downloadable: true,
content_hash: '77da2ab8c10808a72062a8cb809543f8372ba763519fdea0ff6d59b4c76eaa57'
}

 

Здравко
Legendary | Level 20

@biswas_nu wrote:

This value comes however in case of user file

...


Hm..🤔 To be honest, I'm not certain what exactly you mean here.

If you mean that when you get token for non-team account or token for a team member without team scopes it works, then of course would be strange to be otherwise. Such a token doesn't represent a team, but a person (either as an account owner or pointing precise team member - not the entire team). That's why in such a case you don't need to specify exact person explicitly - it's already specified on authentication and associated to the token.

If you mean something else, clarify what you mean exactly.

Hope this clarifies matter.

Greg-DB
Dropbox Staff

[Cross-linking for reference: https://stackoverflow.com/questions/78980867/issue-listing-team-folders-with-dropbox-javascript-sdk ]

 

I see Здравко already helpfully offered some guidance here. The following resources may also serve as useful references:

 

If you have any remaining questions, feel free to reply and clarify.

biswas_nu
New member | Level 2

Hello Legendary

 

Let me explain the problem in detail

biswas_nu
New member | Level 2

When using selectAdmin : <team_member_id of admin>  and calling listfolder and listfoldercontinoue with the folder id, I am able to see all the files in team folder but not their path

 

biswas_nu
New member | Level 2

When using selectAdmin : <team_member_id of admin>  and calling listfolder and listfoldercontinoue with the folder id, I am able to see all the files in team folder but not their path

the data does not contain the filePath for the team files

 

Здравко
Legendary | Level 20

@biswas_nu, Can you take a look on your result posted above? You may see there files "path_lower" and "path_display". Do they absent in some of your list results? 🧐 That's the paths of all entries - files and folder in the list results.

Something that may confuse you is that such paths are rooted to the selected namespace (in your case - member home folders or shared team folders). Leading folder names are missing and if you don't know where you can find them - in your list results for such folders you made at the beginning (where your team_folder_id comes from).

Some other confusion may be incorrect paths symbols case - even in display paths. Only last entry in such a path is guaranteed correct. All preceding, if any, may be messed - messed path symbols case!

If something else confuse you, again, be more concrete.

biswas_nu
New member | Level 2

Hello @Здравко 
They are missing in case of team folder files when access them using selectAdmin: <team member id>

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Здравко Legendary | Level 20
  • User avatar
    biswas_nu New member | Level 2
What do Dropbox user levels mean?