function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dejan CvetkoskiDejan Cvetkoski 

Upload file to dropbox with api

Anyone help me. How i can upload file to dropbox with dropbox api?  Thanks
Kartheek VarmaKartheek Varma
Hi,
This below code will help you
 HttpRequest req = new HttpRequest();
        req.setEndpoint('https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings');
         req.setbody('path='+path+',settings: {"requested_visibility": "public"}');
       // {"path": '+path+',"settings": {"requested_visibility": "public" }   }
        req.setHeader('Authorization', 'Bearer ' + Label.DropboxAPI);
        req.setHeader('Content-Type','application/json');
        req.setMethod('POST');
        req.setTimeout(60000);
        Http h = new Http();
        HttpResponse res = h.send(req);
        string jsonResponse = res.getBody();
       
        system.debug('Response ->' + jsonResponse);
Kartheek VarmaKartheek Varma
How to get link Dropbox to Salesforce get the link please help me ...
Dejan Cvetkoski 9Dejan Cvetkoski 9
Can you tell me what is your problem with that request?
Kartheek VarmaKartheek Varma
Hi,
 public static String getLink(String path_lower){
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings');
        req.setHeader('Authorization', 'Bearer JJJX68WdGNAAAAAAAAAutYW7HvDKVrbhSCiEDxEUuAitEgMIgoZWKZvrE9pI2TwB');
        req.setHeader('Content-Type','application/json');
        req.setbody('path='+path_lower+'Body');
        String Body ='{"settings":{"requested_visibility": "public" }';
              
        
        req.setMethod('POST');
        req.setTimeout(60000);
        Http h = new Http();
        HttpResponse res = h.send(req);
        string jsonResponse = res.getBody();
       
        system.debug('Response ->' + jsonResponse);
        Map<String, Object> response = (Map<String, Object>) JSON.deserializeUntyped(jsonResponse);
        return (String)response.get('url');
    }
I am update the dropbox api 2.0 .This code is getiing error 400 .please help me the solution.
Kartheek VarmaKartheek Varma
15:56:52.0 (533358511)|CALLOUT_REQUEST|[3536]|System.HttpRequest[Endpoint=https://content.dropboxapi.com/2/files/upload, Method=POST] 15:56:53.357 (1357175801)|CALLOUT_RESPONSE|[3536]|System.HttpResponse[Status=OK, StatusCode=200] 15:56:53.357 (1357299024)|USER_DEBUG|[3537]|DEBUG|vcr---response---System.HttpResponse[Status=OK, StatusCode=200] 15:56:53.357 (1357389557)|USER_DEBUG|[3540]|DEBUG|vcr---response---{"name": "UGLE2018020874.pdf", "path_lower": "/flame student documents/2017/contacts/ugle2018020874/applicationpdf_admitcard_documents/ugle2018020874.pdf", "path_display": "/FLAME Student Documents/2017/Contacts/UGLE2018020874/ApplicationPDF_AdmitCard_Documents/UGLE2018020874.pdf", "id": "id:_JBVqgU_WDAAAAAAAAAAEQ", "client_modified": "2017-09-07T02:30:05Z", "server_modified": "2017-09-07T02:30:05Z", "rev": "b5c2d7037", "size": 0, "content_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"} 15:56:53.357 (1358046158)|USER_DEBUG|[3547]|DEBUG|Updated/flame student documents/2017/contacts/ugle2018020874/applicationpdf_admitcard_documents/ugle2018020874.pdf 15:56:53.357 (1359566438)|CALLOUT_REQUEST|[3589]|System.HttpRequest[Endpoint=https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings, Method=POST] 15:56:53.357 (1703976414)|CALLOUT_RESPONSE|[3589]|System.HttpResponse[Status=Bad Request, StatusCode=400] 15:56:53.357 (1704098657)|USER_DEBUG|[3592]|DEBUG|Response ->Error in call to API function "sharing/create_shared_link_with_settings": request body: could not decode input as JSON 15:56:53.357 (1704467112)|USER_DEBUG|[3482]|DEBUG|Exception : Unexpected character ('E' (code 69)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [1,2] 15:56:53.357 (1731662245)|VF_SERIALIZE_VIEWSTATE_BEGIN|0662800000874XY
Santosh VyavhareSantosh Vyavhare
Hi Kartheek Varma
what is the value of path in your code.


Thnaks.
priyanshu nemapriyanshu nema
Hi,
This below code is working for upload file from salesforce to dropbox.
           blob  b = yourPdf;
           Http http = new Http();
            HttpRequest req = new HttpRequest();
            req.setEndpoint('https://content.dropboxapi.com/2/files/upload');
            req.setMethod('POST');
            req.setHeader('Content-Type', 'multipart/form-data');
            req.setHeader('Authorization','Bearer '+AccessToken);
            req.setHeader('Content-Type', 'application/octet-stream');
           req.setHeader('Dropbox-API-Arg','{"path":"folderNmae+'/'+fileName+'.pdf","mode":"add","autorename":true,"mute":false,"strict_conflict":false}');
req.setBodyAsBlob(b);
            req.setTimeout(120000);
            HttpResponse res = http.send(req);
Naveen KNNaveen KN
A detailed post on integrating Salesforce with Dropbox

https://www.codekiat.com/2019/07/salesforce-dropbox-integration-a-complete-guide.html

--
Naveen K N
Carol LoudCarol Loud
You can try Skyvia (https://skyvia.com/data-integration/integrate-salesforce-dropbox) as a solution. It is a no-code cloud ETL tool.