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.