Accessing Dropbox Using REST API in Salesforce

Dropbox allows the user to store and access the files and share with anyone on the fly. Once you have saved files on Dropbox, you can access them from anywhere from your account with the help of Internet.

Dropbox access allows the user to store and access the files and share with anyone on the fly. Once you have saved files on Dropbox, you can access them from anywhere from your account with the help of Internet. We can also synchronize our account to devices by the app. It also allows us to access to the authorized customer’s files via our Mobile Apps / Web application through REST API.

Features: 

  1. We can store our files on our account once and can access it anywhere across all your devices.
  2. Devices are synchronized automatically once if the app is installed.
  3. We can share our files to anyone.
  4. We can save videos, photos, presentation, and many more to your Dropbox.
  5. Our files are safe and no need to maintain manual backups.
  6. We can also have business / enterprise account and share files across our teams efficiently.
  7. Dropbox provides free storage files for individuals and further can extend on pricing as their needs and requirements.

Now, it’s possible to integrate Dropbox with Salesforce that provides access to your customer’s files.

Prerequisites for Dropbox  

  • Create an account in dropbox and verify the account by using the registered email address.
dropbox access

Figure 1: Create an dropbox account 

  1. Choose an API as Dropbox API
dropbox access

Figure 2: Choose Dropbox API 

  1. Choose the access type either as Full Dropbox or a particular folder that you are going to provide access for file storage from Salesforce.
dropbox access

Figure 3: Choose the access type 

  1. Provide the name for your app. (ex. Salesforce_Metadata).

Figure 4: Name the app 

  1. Note down the App key and App secret.
  2. Redirect is the URI where you are going to launch the Visualforce page URL (Say for ex. https://<your-domain>.visual.force.com/apex/<visualforcepage>)
how to access dropbox

Figure 5: Settings 

Steps to be completed in Salesforce

  1. Create a Visualforce Page (ex. Dropbox) and a CommandButton to redirect to Dropbox to provide Single Sign On
  1. Create an Apex Controller (e.x. DropboxController_AC)
  2. Define the required constants needed for the REST API to collaborate with the Dropbox
how to access dropbox
  1. Define a method to execute the web service to get the response for the request provided with endpoint, parameters, headers, and body of the request.
how to access dropbox

Collaborating with Dropbox – Endpoints explained

Reference for Endpoints to build REST API

  • Authorization

The button on the Visualforce page redirects to Dropbox account. Once the user signs into their account, it redirects back to the Visualforce page along with the state we provided and code generated from Dropbox.

Endpoint: https://www.dropbox.com/1/oauth2/authorize

HTTP METHOD: GET

PARAMETERS:

response_type = code / token;

client_id = App key;

redirect_uri = Salesforce Visualforce page;

state = arbitrary data (max 500 bytes);

how to access dropbox
  • Token Generation

Once the authorization is done, it is redirected to our Visualforce page.

Endpoint: https://api.dropboxapi.com/1/oauth2/token

HTTP METHOD: POST

PARAMETERS:

code = code returned as parameter in query string;

grant_type  = authorization_code

client_id = App key;

client_secret = App Secret;

redirect_uri = Salesforce Visualforce page;

SAMPLE RESPONSE:

  • Accessing Dropbox

Once the access_token is returned, all requests should be made using the token in request header.

  1. Get Account information of Logged in user

Endpoint: https://api.dropboxapi.com/1/account/info

HTTP METHOD: GET

HEADERS:

Authorization = Bearer <your-access-token>

SAMPLE RESPONSE:

how to access dropbox
  1. Upload a file

Endpoint: https://content.dropboxapi.com/1/files_put/auto/<directory/filename.extesion>

HTTP METHOD: PUT

HEADERS:

Authorization = Bearer <your-access-token>

BODY:

file = binary data of your file uploaded

SAMPLE RESPONSE:how to access dropbox

Conclusion 

Though Dropbox is a file storage app on cloud, there might be a controversy that why we don’t use the Salesforce itself for file saving options. Of course, the controversy exists but it’s just another favorable solution for the users to save their files directly in Dropbox.

About MST

At MST Solutions our cornerstone is to adapt, engage and create solutions which guarantee the success of our clients. The talent of our team and experiences in varied business verticals gives us an advantage over other competitors.

Recent Articles

Work with us.

Our people aren’t just employees, they are key to the success of our business. We recognize the strengths of each individual and allow them time and resources to further develop those skills, crafting a culture of leaders who are passionate about where they are going within our organization.