How to GET all files from the Dropbox API

Dropbox is a cloud-based file storage hosting and sharing platform that offers solutions across enterprise and consumer. They have deep integrations with workplace and collaboration platforms and many larger companies use Dropbox to collaborate and share assets. A common query when it comes to using the Dropbox API is how to GET all files from the Dropbox API and how to handle authentication.

We’ll be using Postman to demonstrate how to get Dropbox files via the API.

{{blog-cta-100+}}

Getting Files from Dropbox

Preparation

In order to access Dropbox’s API, you’ll first need a sandbox Dropbox account, as well as an OAuth application to get an access token.

The best way to get both of these is to create a Dropbox developer account.

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.

And now you’ve set up your developer account as well as an OAuth app!

To get a sandbox Dropbox account, simply sign up for a free account here.

Related: How the most popular file storage APIs work

Getting files & folders from Dropbox

Create a new collection in Postman. In the Authorization section, select Bearer Token as the type. Copy and paste your access token into Token.

At the highest level, Dropbox is organized by namespaces. To access the namespaces, make the following API call:

POST https://api.dropboxapi.com/2/team/namespaces/list


Before accessing the files in the namespace, you’ll need a user’s account ID. This is required by Dropbox to impersonate a user to access files and folders. Make an API call to:

POST https://api.dropboxapi.com/2/team/members/list

To access all files and folders within the namespace, including nested folders and files, you’ll need the following.

Make an API call to:

POST https://api.dropboxapi.com/2/files/list_folder

Include <code class="blog_inline-code">Dropbox-API-path_Root</code> in the header, with the following header value:

{".tag": "root", "root": "[INSERT NAMESPACE ID]"}

Include <code class="blog_inline-code">Dropbox-API-Select-Admin</code> in the header, with header value equal to any of the admin <code class="blog_inline-code">team_member_id</code> from the previous step.

Add the path of the namespace in the path, add 2 parameters:

<code class="blog_inline-code">path</code> to indicate which folder or namespace to pull from. Here, use the namespace id, and prepend it with <code class="blog_inline-code">ns:</code>.

<code class="blog_inline-code">recursive</code> to indicate whether to get nested files and folders, not just the immediate files & folders under the namespace. Here, set to true.

The initial API call will most likely not return all files and folders. You’ll have to use cursor-based pagination, and you’ll make a call to:

POST https://api.dropboxapi.com/2/files/list_folder/continue

That wraps up how to get all files and folders in your Dropbox account via API!

Related: A guide to retrieving folders from the Dropbox API via Python

Building a production-level integration

There are a few factors to consider when turning this simple POC into a production-level integration:

  • You’ll need to implement cursor-based pagination. Dropbox uses a separate endpoint <code class="blog_inline-code">https://api.dropboxapi.com/2/files/list_folder/continue</code> with a provided cursor to output the rest of the response. This is especially important so that you don’t miss any data.
  • If you need to do periodic syncs, you’ll also need to implement periodic polling of the Dropbox APIs. You’ll also have to implement rate-limit handling to make sure you don’t exceed Dropbox’s rate limits.
  • You’ll need to implement logic to handle the Dropbox OAuth flow, including providing a redirect URI and a bit of front-end support. You’ll be unable to use the expiring access token for production purposes.

Conclusion

This article showed you how to GET all files from Dropbox.

As your integration needs grow, Merge connects your product to hundreds of integrations with one single API in HR, recruiting, accounting, ticketing, CRM, and marketing automation.

If your organization needs to not only GET files from Dropbox, but also SharePoint, Box, Google Drive, and others, check out the Merge File Storage Unified API! As with all of Merge’s Unified APIs, one API connection is enough to offer your users integrations to all File Storage platforms.

Learn more about Merge by scheduling a demo with one of our integration experts.