We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here. 

Forum Discussion

Aryahagh's avatar
Aryahagh
New member | Level 2
5 years ago

Reading programmatically several files from Dropbox business

Hi I want to read (or only reading is not possible, download) several files in different folders ,which is stored in a Dropbox buisiness account, programmatically in python. I were able to create a...
  • Greg-DB's avatar
    5 years ago

    If you only want to access the files in one particular account, you can register a "Dropbox API" app with the "Full Dropbox" permission and then use the /2/files/download endpoint to download files from a connected account without any extra configuration. (You can also connect the app to multiple different accounts, but each user would need to authorize their own account, to give the app a distinct access token for each one.) That would look like this:

     

    curl -X POST https://content.dropboxapi.com/2/files/download \
        --header "Authorization: Bearer <ACCESS_TOKEN>" \
        --header "Dropbox-API-Arg: {\"path\": \"/test.txt\"}"

     

    Or, using the Python SDK:

     

    dbx = dropbox.Dropbox(ACCESS_TOKEN)
    
    print(dbx.files_download("/test.txt"))

     

    If you want to be able to access the files any team member's account on a Business team, by only having a team admin authorize the app once, you will need to register a "Dropbox Business API" app with the "team member file access" permission and then use the /2/files/download endpoint to download files, but with some extra configuration as covered in the "Member file access" section of the Business API documentation. Since Dropbox Business API apps are connected to the entire Business team, you need to specify which member you want to operate on when making a user-level call, such as /2/files/download. You can do so by specifying the Dropbox-API-Select-User" header with the value being the team member ID of the member you want to call for. The team member ID starts with "dbmid:" and can be retrieved from the Dropbox Business API, such as via /2/team/members/get_info or /2/team/members/list[/continue]. That would look like this:

     

    curl -X POST https://content.dropboxapi.com/2/files/download \
        --header "Authorization: Bearer <TEAM_ACCESS_TOKEN>" \
        --header "Dropbox-API-Select-Admin: <TEAM_MEMBER_ID>" \
        --header "Dropbox-API-Arg: {\"path\": \"/test.txt\"}"

     

    Or, using the Python SDK:

     

    dbx = dropbox.DropboxTeam(TEAM_ACCESS_TOKEN).as_user(TEAM_MEMBER_ID)
    
    print(dbx.files_download("/test.txt"))