Table of contents

While Dropbox, the widely-used file storage solution, offers many benefits on its ownâsuch as letting you store documents, photos, and/or videos securely and from any device and locationâit offers even more value when its folders can be accessed by your other internal applications or your product.
Regardless of your specific integration use case, we'll walk through every step you should take to get folders from the Dropbox API using Python.
To follow along, youâll need:
Related: A guide to integrating with the Dropbox API using Python
To access Dropboxâs API, youâll need a sandbox Dropbox account and an OAuth application to get your access token.
To do both, you can follow these steps:
1. Sign up for a developer account here. Click Create apps to sign up.
2. Once youâre done signing up, navigate here and click Create app.â
3. Choose âScoped accessâ and âFull Dropboxâ, so that your app has access to all files & folders.

4. For this article, weâll just be showing you how to access the API. So instead of implementing the full OAuth flow, weâll generate a temporary access token. Click Generate access token to generate an access token. Save the token, as weâll be using it to make API calls.

To get a sandbox Dropbox account, simply sign up for a free account here.
Related: How to get your Dropbox API key
Dropbox uses bearer tokens to make authenticated calls. For any request you make, youâll need to add <code class="blog_inline-code">âAuthorization: Bearer {ACCESS_TOKEN}â</code>, where {ACCESS_TOKEN} is the token you retrieved when creating your Dropbox OAuth application in the previous step.
At the highest level, Dropbox is organized by namespaces. To access folders, you need your root namespace id.Â
To access that, make the following API call: <code class="blog_inline-code">POST https://api.dropboxapi.com/2/users/get_current_account</code>
In the response body, youâll see root_namespace_id under root_info field. This defines your root namespace id.

Related: A guide to connecting Dropbox MCP with Claude Code
Your root-level folders exist at the top-level of your namespace.
To retrieve them, make the following API call:
<code class="blog_inline-code">method = POST</code>
<code class="blog_inline-code">url = https://api.dropboxapi.com/2/files/list_folder</code>
<code class="blog_inline-code">data = {"path": "ns:YOURROOTNAMESPACEID", "limit": 2000â, "recursive": false}</code>
<code class="blog_inline-code">headers= 'Dropbox-API-path_Root: {".tag": "root", "root": "YOURROOTNAMESPACEID"}'</code>

Letâs say you get more than 2000 folders at the root-level. In the previous response, youâll see a cursor value. To paginate, make the following API call:
<code class="blog_inline-code">method = POST</code>
<code class="blog_inline-code">url = https://api.dropboxapi.com/2/files/list_folder/continue</code>
<code class="blog_inline-code">data = {âcursorâ: YOURCURSORFROMPREVIOUSRESPONSE}</code>
<code class="blog_inline-code">headers = 'Dropbox-API-path_Root: {".tag": "root", "root": "YOURROOTNAMESPACEID"}'</code>

Related: A guide to file storage APIs
Now letâs get folders within folders.
To do so, make the following API call:
<code class="blog_inline-code">method = POST</code>
<code class="blog_inline-code">url = https://api.dropboxapi.com/2/files/list_folder</code>
<code class="blog_inline-code">data = {"path": "THEFOLDERID", "limit": 2000â, "recursive": false}</code>
<code class="blog_inline-code">headers = 'Dropbox-API-path_Root: {".tag": "root", "root": "YOURROOTNAMESPACEID"}'</code>

The final python code may look something like what's shown below. We can use depth-first searchâwhich can be more reliable than breadth-first searchâso that you know which root-level folder is done being processed or not (i.e. more accurately track progress).
As you can tell, retrieving folders from Dropbox via API requests can be technically complex and time consuming to set up (and maintain!). These issues only get exacerbated when you consider the other file storage tools your clients want to integrate with your product, such as Box or Google Drive.
To help you integrate with any of your clients' file storage solutions so that your product can access their folders (among other resources), you can simply build to Merge's File Storage Unified API.
You can learn more about Merge and its Unified API by scheduling a demo with one of our integration experts.