We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Vivek K.2
10 years agoNew member | Level 1
Unable to Upload the File into DropBox From Salesforce Using /Files_put API ?
Hi All,
I tried to upload the file into Drop Box account From Salesforce Using /files_put Dropbox Api.But am always getting following Error : [Status=Bad Request, StatusCode=400]{"error": "B...
Vivek K.2
10 years agoNew member | Level 1
Thanks for your response @Gregory.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!
public class DropboxController
{
//Fetched from URL
Public String code ;
Public String accesstoken;
public DropboxController()
{
code = ApexPages.currentPage().getParameters().get('code') ;
//Get the access token once we have code
if(code != '' && code != null)
{
AccessToken() ;
}
}
public PageReference DropAuth()
{
system.debug('UPLOAD'+accessToken );
//Authenticating
// PageReference pg = new PageReference('https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=XXXX&redirect_uri=https://c.cs20.visual.force.com/apex/DropboxPage&state=Mytesting') ;
return null;
}
public void AccessToken()
{
//Getting access token from dropbox
String tokenuri = 'https://api.dropbox.com/1/oauth2/token?grant_type=authorization_code&code='+code+'&redirect_uri=https://c.cs20.visual.force.com/apex/DropboxPage';
HttpRequest req = new HttpRequest();
req.setEndpoint(tokenuri);
req.setMethod('POST');
req.setTimeout(60*1000);
Blob headerValue = Blob.valueOf('XXXX' + ':' + 'YYYY');
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
Http h = new Http();
String resp;
HttpResponse res = h.send(req);
resp = res.getBody();
JSONParser parser = JSON.createParser(resp);
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)){
String fieldName = parser.getText();
parser.nextToken();
if(fieldName == 'access_token') {
accesstoken = parser.getText();
}
}
}
system.debug('accessToken==>'+accessToken );
System.debug(' You can parse the response to get the access token ::: ' + resp);
string token = 'https://api-content.dropbox.com/1/files_put/auto/ProjectListNew.csv';
HttpRequest r = new HttpRequest();
r.setEndpoint(token);
r.setHeader('Authorization','Bearer ' +accesstoken);
r.setMethod('PUT');
r.setTimeout(60000);
List<Project2__c> projlist = [Select id,name,Project_Name__c,Project_Type__c,Project_Status__c from Project2__c LIMIT 10];
string header = 'Record Id, Project Key, Project Name, Project Type, Project Status \n';
string finalstr = header ;
for(Project2__c a: projlist)
{
string recordString = '"'+a.id+'","'+a.Name+'","'+a.Project_Name__c+'","'+a.Project_Type__c+'","'+a.Project_Status__c+'"\n';
finalstr = finalstr +recordString;
}
Blob csvBlob = Blob.valueOf(finalstr);
r.setBodyAsBlob(csvBlob);
Http h1 = new Http();
HttpResponse res1 = h1.send(r);
string resp1 = res1.getBody();
System.debug('Upload Success :: ' + resp1);
}
}