400 Client Error: Bad Request for url: https://api.dropboxapi.com/2/files/list_folder 400 Client Error: Bad Request for url: https://api.dropboxapi.com/2/files/list_folder json json

400 Client Error: Bad Request for url: https://api.dropboxapi.com/2/files/list_folder


First, I should note that we do recommend using the official Dropbox API v2 Python SDK as it takes care of a lot of the underlying networking/formatting work for you. That said, you can certainly use the underlying HTTPS endpoints directly like this if you prefer.

Anyway, when dealing with issues like this, be sure to print out the body of the response itself, as it will contain a more helpful error message. You can do so like this:

print(r.text)

In this case with this code, that yields an error message:

Error in call to API function "files/list_folder": Invalid select user id format

Another issue is that with API v2, the root path is supposed to be specified as empty string, "":

Error in call to API function "files/list_folder": request body: path: Specify the root folder as an empty string rather than as "/".

That's because when using the member file access feature like this, you are supposed to supply the member ID, not the account ID.

So, fixing those issues, the working code looks this:

import requestsurl = "https://api.dropboxapi.com/2/files/list_folder"headers = {    "Authorization": "Bearer MY_TOKEN",    "Dropbox-API-Select-User": "dbmid:MEMBER_ID"    }data = {    "path": "",}r = requests.post(url, headers=headers, json=data)print(r.text)r.raise_for_status()print(r.json())

Edited to add, if you want to use the Dropbox API v2 Python SDK for this, you would use DropboxTeam.as_user like this:

import dropboxdbx_team = dropbox.DropboxTeam("MY_TOKEN")dbx_user = dbx_team.as_user("dbmid:MEMBER_ID")print(dbx_user.files_list_folder(""))