One month down in 2025: How are your resolutions coming along? Check out how to get back on track here.
Forum Discussion
Schwankenson
2 years agoNew member | Level 2
Dropbox API (Python) - How to get access to Team and User files
I created the whole issue with code examples here:
https://stackoverflow.com/questions/77577897/dropbox-api-python-how-to-get-access-to-team-and-user-files
I have a dropox business user which is member of the team. I would like to see the filesystem with the API like when I just login to dropbox.com: Member and team files and folder.
So I'm creating a dropbox authentication code with, but when i`m calling dbx.file_list_folders() I get error
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>.')
I can do something like that:
dbx_team = dropbox.DropboxTeam(ACCESS_TOKEN)
dbx = dbx_team.as_user("YOUR_TEAM_MEMBER_ID")
But then I need to know the "YOUR_TEAM_MEMBER_ID" - And it is not possible to get it from API. Or is it?
I created the whole issue with code examples here:
https://stackoverflow.com/questions/77577897/dropbox-api-python-how-to-get-access-to-team-and-user-files
- ЗдравкоLegendary | Level 20
- SchwankensonNew member | Level 2
This gives same error:
This API function operates on a single Dropbox account, but the OAuth 2 access token you provided is for an entire Dropbox Business team.
- Greg-DB
Dropbox Staff
Schwankenson This error message is referring to specifying what account on the team to operate on behalf of. For reference, when using any "team scopes", the resulting access token is connected to an entire Dropbox team, not an individual account. So, when using a team-scoped access token to access user-specific endpoints, such as /2/files/list_folder (which is what the files_list_folder method in the Python SDK uses), you will need to specify which member of the team you want to operate on behalf of.
To do this, you'd need to specify the 'Dropbox-API-Select-User' header (or 'Dropbox-API-Select-Admin' as needed/desired). The value should be the team_member_id for whichever member you wish to act on behalf of. In the Dropbox Python SDK, that can be set using as_user (or as_admin).You can get the member ID for a team member from a number of different endpoints on the API, such as /2/team/members/get_info_v2, which team_members_get_info_v2 in the Python SDK, or /2/team/members/list_v2//2/team/members/list/continue_v2, which are team_members_list_v2/team_members_list_continue_v2.
Also, note that using any team scopes means that only team admins can authorize the app. If you just want to connect to a particular account though (in which case any account can connect the app, but to their own account only), you can omit the team scopes. The access token without the team scopes will be specific to the particular account (whether on a team or not) and so will not require the additional header. You can find more information on scopes in the OAuth Guide. If you don't need to call any team endpoints, e.g., if you just need to call individual endpoints, such as /2/files/list_folder (files_list_folder), I recommend this solution instead for simplicity and security.- SchwankensonNew member | Level 2
Thank you. I understand the error message. But when I create the Authentication Code, I have to authenticate at dropbox with a specific account. And I do not understand, why this specific account is not saved in the authentication code.
What I now do is, looping through the team members and use as_user() to a user with a specific email address. But this is really clunky I think.- Greg-DB
Dropbox Staff
While a particular team admin account is needed to authorize the app when using any team scopes, the resulting connection is to the entire team, not just that particular account. You can check which account was used to authorize a particular team-linked access token though by calling /2/team/token/get_authenticated_admin (team_token_get_authenticated_admin).
If you do only need to connect to the one account, I recommend omitting the team scopes instead, so that the connection would be to a specific account and you wouldn't need to use as_user.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,947 PostsLatest Activity: 4 hours ago
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 or Facebook.
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!