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 to provide the Dropbox-API-Select-User HTTP header with python API

How to provide the Dropbox-API-Select-User HTTP header with python API

VahagnGhaz
Explorer | Level 3

Hi ! I've generated access token for Business App, and tried to make simple request 

dbx = dropbox.Dropbox(my_token)
dbx.files_list_folder(path).entries

But I got  

dropbox.exceptions.BadInputError:  '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

And from given documentation there is a part saying:   Specify the member_id of the user that the app wants to act on using a custom HTTP header called Dropbox-API-Select-User.

I just got stuck and need help for spicifying Dropbox-API-Select-User via python or in other ways if there are so. 

Additional info: I have  team admin permissions 

                            Permission type for app is  Team member file access               

6 Replies 6

Greg-DB
Dropbox Staff

In the Dropbox Python SDK, you can specify this header using DropboxTeam.as_user.

You can get the team member IDs from a number of places, such as DropboxTeam.team_members_get_info, or DropboxTeam.team_members_list/DropboxTeam.team_members_list_continue.

VahagnGhaz
Explorer | Level 3

Thanks for your reply. Everything works fine, but now I have another issue. All I need to list, write ...  in TEAM shared folder, but  when I use 

self.dbx.files_list_folder(self.path).entries  

I got ['Get Started with Dropbox Paper.url', 'Get Started with Dropbox.pdf'], which is my private folder content. So is there any way to access shared folder ?  

Greg-DB
Dropbox Staff

By default, API calls will operate in the private team member folder. It sounds like you want to access the team space though. To do so, you need to set the "path root" for the API call to be the team space. 

I recommend reading the Namespace Guide, which covers this in detail.

In the Python SDK in particular, to specify a particular root, you should use with_path_root. For example:

dbx.with_path_root(dropbox.common.PathRoot.root("XXXXXXXXX")).files_list_folder("")

or:

dbx.with_path_root(dropbox.common.PathRoot.namespace_id("XXXXXXXXX")).files_list_folder("")

 

VahagnGhaz
Explorer | Level 3

I got :: > dropbox.exceptions.PathRootError: PathRootError('2f7ac7e2ce9abb921272552f987f63b3', PathRootError('no_permission', None)),

when try to run this command, so for permission do I need to make business app?

self.dbx.with_path_root(dropbox.common.PathRoot.namespace_id("2")).files_list_folder("")

 

VahagnGhaz
Explorer | Level 3

Actuall I have this structure, and all I need to do is work with shared ELEMENTS folderScreenshot from 2019-07-18 22-14-38.png

VahagnGhaz
Explorer | Level 3

Okay! I got that ! thanks for your support.  Just in case someone has this issue too, here is my solution 

dbx = dropbox.Dropbox(my_token)
root_namespace_id = dbx.users_get_current_account().root_info.root_namespace_id
dbx = dbx.with_path_root(PathRoot.namespace_id(root_namespace_id))

 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    VahagnGhaz Explorer | Level 3
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?