Ruby client library for Dropbox API v2
Branch: master
Clone or download
Latest commit 24f94b0 Feb 16, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin Prepare for release. Aug 2, 2016
docs Updates documentation Feb 16, 2019
lib Bump version Feb 16, 2019
spec Use official doc copy from Dropbox Feb 16, 2019
yardoc Improves documentation. Jan 7, 2017
.gitignore Updates docs, getting rid of gh-pages branch Nov 12, 2018
.rspec Updated settings for RSpec and VCR. Apr 9, 2016
.travis.yml Adds Ruby 2.6 to CI Feb 16, 2019
.yardopts Updates docs, getting rid of gh-pages branch Nov 12, 2018 Completes implementation of `list_folder_members`. Oct 22, 2016
Gemfile Updates dependencies Jul 21, 2018
LICENSE Initial commit Mar 5, 2016 Updates README to explain dependencies Jul 21, 2018 Adds a release guide Oct 3, 2017
Rakefile Started building a tool to build test fixtures. Jan 25, 2017 Updates project documents. Oct 22, 2016
dropbox_api.gemspec Updates dependency on Faraday, support 0.15.4 Feb 16, 2019 Updates documentation. Oct 23, 2016


Library for communicating with Dropbox API v2.


Add this line to your application's Gemfile:

gem 'dropbox_api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dropbox_api


Please, refer to this gem's custom Dropbox API documentation. Most of the time you'll be checking the available endpoints.

Unfortunately, the documentation at is disrecommended because it lacks some nice features that have been added with YARD plugins:

  • Each endpoint includes its tests right below the description, this works as an example of its usage.
  • All endpoints are shown as methods of the Client class, just as you will use them.

Basic set up

Authorize your application

Dropbox uses OAuth, in order to use this library from your application you'll have to get an authorization code.

Once you have it, just pass it on client initialization:"VofXAX8D...")
#=> #<DropboxApi::Client ...>

Or set it as an ENV variable called DROPBOX_OAUTH_BEARER, for example:

#=> #<DropboxApi::Client ...>

Note that setting an ENV variable is only a feasible choice if you're only using one account.

Option A: Get your access token from the website

The easiest way to obtain an access token is to get it from the Dropbox website. You just need to log in to Dropbox and refer to the developers section, go to My apps and select your application, you may need to create one if you haven't done so yet.

Under your application settings, find section OAuth 2. You'll find a button to generate an access token.

Option B: Use DropboxApi::Authenticator

You can obtain an authorization code with this library:

authenticator =, CLIENT_SECRET)
authenticator.authorize_url #=> ""

# Now you need to open the authorization URL in your browser,
# authorize the application and copy your code.

auth_bearer = authenticator.get_token(CODE) #=> #<OAuth2::AccessToken ...>`
auth_bearer.token #=> "VofXAX8D..."
# Keep this token, you'll need it to initialize a `DropboxApi::Client` object

Standard OAuth 2 flow

This is what many web applications will use. The process is described in Dropbox's [OAuth guide] (

If you have a Rails application, you might be interested in this setup guide.

Performing API calls

Once you've initialized a client, for example:

client ="VofXAX8D...")
#=> #<DropboxApi::Client ...>

You can perform an API call like this:

result = client.list_folder "/sample_folder"
#=> #<DropboxApi::Results::ListFolderResult>
#=> [#<DropboxApi::Metadata::Folder>, #<DropboxApi::Metadata::File>]
#=> false

The instance of Client we've initialized is the one you'll be using to perform API calls. You can check the class' documentation to find all available endpoints.

Large file uploads

If you need to upload files larger than 150MB the default #upload endpoint won't work. Instead, you need to start a upload session and upload the file in small chunks.

To make this easier, the method upload_by_chunks will handle this for you, example:

client ="VofXAX8D...")
#=> #<DropboxApi::Client ...>"large_file.avi") do |f|
  client.upload_by_chunks "/remote_path.txt", f

Check out the method documentation to find out all available options.


This gem depends on oauth2 and faraday.

It has official support for Ruby versions 1.9.x and 2.x.


After checking out the repo, run bin/setup to install dependencies. Then, run bin/console for an interactive prompt that will allow you to experiment.


I recommend you to use a test account other than your main one.

We use VCR to record the HTTP calls to Dropbox, however we sometimes need to regenerate the cassettes. Let's take list_folder as an example to show what would be the procedure to do so:

  1. Manually delete the existing cassettes in spec/fixtures/vcr_cassettes/list_folder/*.yml.

  2. Run the task to build the scaffolding in your Dropbox account so the tests will pass. If it doesn't exist you may need to write it yourself, check the DropboxScaffoldBuilder class to find all existing scaffold builders.

    DROPBOX_OAUTH_BEARER=YOUR_AUTH_BEARER rake test:build_scaffold[list_folder]
  3. Run the tests and the cassettes will be written:

    DROPBOX_OAUTH_BEARER=YOUR_AUTH_BEARER rspec spec/endpoints/files/list_folder_spec.rb

The OAuth bearer shouldn't have been recorded in the cassette and it should've been filtered. However, you may want to double check before pushing your updates to Github.

Tip: You can simply run export DROPBOX_OAUTH_BEARER=YOUR_AUTH_BEARER at the beginning of your work session so you don't need to prefix it in every command line.


Any help will be much appreciated. The easiest way to help is to implement one or more of the endpoints that are still pending. To see how the endpoints are implemented, check out the lib/dropbox_api/endpoints folder.