Hi All,
Today I will show you how to copy files to Dropbox from Salesforce using Dropbox integration.
You don’t need to buy costly AppExchange apps or services like Zapier to do this. We will show you how to do this with a simple Apex class.
First of all, we need is a Dropbox account and a Salesforce org with which we will integrate with.
If you don’t have a Dropbox account, you can get one at https://www.dropbox.com/. We have one already, so we won’t be signing up again.
Dropbox SignUp pag1
Fill up the form, and you will get your Dropbox account.
Now, go to the developer section of Dropbox. To do so type https://www.dropbox.com/developers in the URL and press Enter. Here we will be creating a Dropbox app that will act as a listener between the Salesforce org and the Dropbox account.
Dropbox developer page
Click on Create your app tab to start creating the app.
Create app page in Dropbox
On the next page, select Dropbox API, and access as Full Dropbox. Give a name to your app and click on Create app button.
(Refer to the image below to create the app)
App settings
After the app is created, there are a few more settings you need to do to proceed. Keep the App key and App secret handy. You have to update the Redirect URIs in the OAuth 2 section later on.
App advanced settings
Now, create the Visualforce page from where you will be uploading the files to Dropbox. Set the URL of the visual force page in the Redirect URIs of the Dropbox app. (image below)
Update the Redirect URI with vf page URL
Click the Dropbox login button to log in to Dropbox and authorise it to upload files to your Dropbox account.
Click Dropbox login
Login to your Dropbox account to give authorisation.
Login to Dropbox
Now you can see the email id of the connected Dropbox account and a file uploaded.
Select a file and Upload to Dropbox.
Select file and Upload
[code language=”java”]
public DropboxUploadController() {
connected = false;
success = false;
apiKey = ”; // this is your dropbox apikey
apiSecret = ”; // this is your dropbox api secret
redirectURI = ‘https://souravmoy-dev-ed–c.ap2.visual.force.com/apex/DropboxUpload’; // url of the vf page in which the dropbox login is done
Dropbox_Account_endpoint = ‘https://api.dropboxapi.com/1/account/info’;
Dropbox_files_endpoint = ‘https://content.dropboxapi.com/1/files_put/auto/’;
Dropbox_OAuth_authorize = ‘https://www.dropbox.com/1/oauth2/authorize’;
Dropbox_OAuth_token = ‘https://api.dropboxapi.com/1/oauth2/token’;
code = ApexPages.currentPage().getParameters().get(‘code’);
if(code != null) {
connected = true;
authorizationCode = code;
getRefreshToken();
retrieveUserInfo();
}
}
[/code]
In lines 4, 5 write the App Key and App Secret of your Dropbox app.