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
saurabhguptasaurabhgupta 

Salesforce-WatchDox Integration for Uploading documents

 

Hi All
 
I m quite new in salesforce Integartion.
I m working on  a Integrating salesforce to watchdox
Watchdox is actually meant for protecting Documents
 
I have the API which I need to used and also I have succeded in esatablishing a connection between watch dox and salesforce using LOGIN
 
Next I need to uplaod the document to the watchdox
 
I m pasting here the my code
 

 

Hi All 

I m quite new in salesforce Integartion.

I m working on  a Integrating salesforce to watchdox

Watchdox is actually meant for protecting Documents 

I have the API which I need to used and also I have succeded in esatablishing a connection between watch dox and salesforce using LOGIN

 Next I need to uplaod the document to the watchdox

 I m pasting here the my code 

 

 

 

Hi All

 

I m quite new in salesforce Integartion.

I m working on  a Integrating salesforce to watchdox

Watchdox is actually meant for protecting Documents

 

I have the API which I need to used and also I have succeded in esatablishing a connection between watch dox and salesforce using LOGIN

 

Next I need to uplaod the document to the watchdox

 

I m pasting here the my code

 

 

public static void getWatchDocs() 

    {

 

 

 

       // String url= 'https://api.watchdox.com/login?User name='+UserName+'&Password='+Password;

        String url= 'https://api.watchdox.com/session';

        Http h = new Http();

       // Instantiate a new HTTP request, specify the method (Post) as well as the endpoint

        HttpRequest req = new HttpRequest();

 

        req.setEndpoint(url + '/' + UserName);

        System.debug(url + '/'+ UserName);

        req.setMethod('POST');

 

       req.setHeader('Content-Type', 'application/json; charset=UTF-8');

       req.setHeader('x-wdox-version', '1.0');

 

       req.setBody(' { \"password\" : \"' + Password + '\" } ');   

       System.debug('request is........' + req.getBody());

       System.debug('request header is........' + req.getHeader('x-wdox-version'));

 

        HttpResponse res;        

        String resURL;

        res = h.send(req);

        String Data = res.getHeader('x-wdox-ssid');

        System.debug('reponse is........' + res);

        System.debug('reponse is........' + res.getBody());

        System.debug('reponse header is........' + res.getHeaderKeys() + '.....'+res.getHeader('x-wdox-ssid'));

        System.debug(data);

        sessid=res.getHeader('x-wdox-ssid');

        getguid();

        //getdocs(res.getHeader('x-wdox-ssid'));

    } 

    public static void getguid()

    {

       String url1= 'https://api.watchdox.com/document';

        Http h1 = new Http();

       // Instantiate a new HTTP request, specify the method (Post) as well as the endpoint

        HttpRequest req1 = new HttpRequest();

 

        req1.setEndpoint(url1);

        System.debug(url1);

        req1.setMethod('GET');

       //req.setHeader('Content-Type', 'application/json; charset=UTF-8');

       req1.setHeader('x-wdox-version', '1.0');

       req1.setHeader('x-wdox-ssid', sessid);//'aB9Ctg5U1t3Z6DYLmk2ShLNFrz4wrnRBBS4unt4deKswTQgOIuwe5DWCpUEu/VWU7d6vBq4.kntvAC02gwc.4ZSCZfkAZs4g5VLiNX1LaU/0');

       System.debug('request header is........' + req1.getHeader('x-wdox-version')); 

       System.debug('request header is........' + req1.getHeader('x-wdox-ssid')); 

 

       HttpResponse res1;        

       String resURL1;

       res1 = h1.send(req1);

       guid=res1.getBody(); 

 

       System.debug(guid);

       uploaddocs();

}

 

public static void uploaddocs()

 

{    

        String subguid=guid.substring(9,45);

        System.debug(subguid);

        String FileName = 'sample.doc.docx';

        //Blob bodyContent=blob.valueof('FileName');

        //system.debug( bodyContent );

        String url2= 'https://api.watchdox.com/document';

 

        Http h2 = new Http();

        HttpRequest req2 = new HttpRequest();

        req2.setEndpoint(url2 + '/' + subguid + '/upload');

        System.debug(url2);

        req2.setMethod('POST');

        req2.setHeader('Content-Type', 'multipart/form-data');

        req2.setHeader('x-wdox-version', '1.0');

        req2.setHeader('x-wdox-ssid', sessid);

 

        // req2.setBody('{ filename= ' + NewDocument + ' ,Data= BYTE[] }'); 

 

        System.debug('request is........' + req2.getBody()); 

        HttpResponse res2;        

        String resURL2;

        res2 = h2.send(req2); 

 

}

 

}

 

 

 

But in this code in upload docs method I m having errors .

 

When I contacted the watchdox support they provided me the following information which is required to be added

 

The following link http://code.activestate.com/recipes/146306-http-client-to-post-using-multipartform-data/ has an example written in python how a mutlipart request can be manually constructed.

 

For example, suppose I wanted to send the file name "hello.bin" who's content was 10 lines containing the number 12345.

In the header, 

set x-wdox-version to         1.0

set x-wdox-ssid to the ssid you get from the login procedure

set content-type to              multipart/form-data; boundary=----------ThIs_Is_

tHe_bouNdaRY_$

 

The body of the post should be 

 

------------ThIs_Is_tHe_bouNdaRY_$

Content-Disposition: form-data; name="data"; filename="hello.bin"

Content-Type: application/octet-stream

 

12345

12345

12345

12345

12345

12345

12345

12345

12345

12345

 

------------ThIs_Is_tHe_bouNdaRY_$--

Since I m quite new in using web services and not even aware of phython i want to translate this information in Apex syntax

For req.Header i have written the Apex syntax

but facing problems in using req.Body ( ) in Apex syntax for the above requirement.Actually I need to pass filename and file data in request Message Body

May be I have to use Blob here .

Can anyone help please?

 

 

 

 

Thanks 

SuperfellSuperfell

Apex callouts don't have any support for blob types.

gv007gv007

Saurav,

             Can you explan are you doing it an and Proff or cocept .What is yours actuval expected size of upload in real time.

Thanks

Gopi

 

saurabhguptasaurabhgupta

Hi Gopi

 

I m working on integrating salesforce to watchdox

Watchdox is basically a website where one can upload his documents and set users and  access permissions these users will have

 

https://www.watchdox.com/

 

so currently  I have stored a document in standard object Document

and i have  to upload it on watchdox

 

In the above code you can see that in my class  i have three static methods

1) public static void  getWatchDocs()  - to establish a connection between salesforce and watchdox

2) public static void  getguid()  -  to get the GUID which is actually required as we need it in the method to upload  document

 

3)public  static void uploaddocs() -  this method is for uploading document

 

  From the previous code i have made changes in my code  

  I m pasting my recent code  for uploaddocs method :

 

  public  static void uploaddocs()

{       
        String subguid=guid.substring(9,45);
        System.debug(subguid);
        Document Doc =[Select Name, Id, Body From Document ];
        System.debug('Doc' + Doc);
        String FileName = Doc.Name;
        BodyContent=Doc.Body;
        
        System.debug( 'FileName' + FileName  );
        System.debug( 'BodyContent' + BodyContent  );
      
        
        String url2= 'https://api.watchdox.com/document';
        
        Http h2 = new Http();
        HttpRequest req2 = new HttpRequest();
        
       String DocBody =  bodyContent.toString();
                    
       String requestBody =  '----------ThIs_Is_tHe_bouNdaRY_$ \n'+
                   'Content-Disposition: form-data; name="data"; filename="' + FileName+ '" \n'+
                   'Content-Type: application/octet-stream\n'+
                   '\n'+
                     BodyContent+
                   '\n\n' +
                   '------------ThIs_Is_tHe_bouNdaRY_$--\n';
        Integer bodyLength  =requestBody.length();                     
        
        req2.setEndpoint(url2 + '/' + subguid + '/upload');
        System.debug(url2);
        req2.setMethod('POST');
        
        req2.setHeader('Content-Type', 'multipart/form-data;boundary=----------ThIs_Is_tHe_bouNdaRY_$');
      
        req2.setHeader('Content-Length','bodyLength');
        req2.setHeader('x-wdox-version', '1.0');
        req2.setHeader('x-wdox-ssid', sessid);
        req2.setBody(requestBody);
        System.debug('request is........' + req2.getBody());
        HttpResponse res2;        
        String resURL2;
        res2 = h2.send(req2);
        

 

  I m facing error in this method .

  The error is related to some badrequest having http status code 400 which says either some information is invalid or  missing

  I m in touch with the watchdox support team and I have done what ever they have suggested

  Can anyone help and suggest what information  is probably missing or invalid?

 

 

Thanks

Saurabh

 

 

 

saurabhguptasaurabhgupta

Hi All

 

 since the previous approach is not working  I m also trying to follow a different approach to do this

 Some one suggested it so i m using this approach

 

I have a created a VF page and a controller

when the page gets loaded the controller is executed first and the connection with watch dox is established

Then I am using  the VF page to select the document which needs to be uplaoded

 

I have set the endpoint URL in the VF page like this

 

<form enctype="multipart/form-data" action="https://api.watchdox.com/document/{!subguid}/upload" method="post">

 

but I dont know if I can send the following request information using any Visual Force  or HTML tag or any other solution

 

 

req2.setHeader('x-wdox-version', '1.0');

req2.setHeader('x-wdox-ssid', sessid);

 

 

I search also but could not get a appropriate solution

If anyone can provide a solution it will be great?

 

Thanks

Saurabh

 

 

dhritidhriti

HI I am trying to do something similar , is it possible to make HTTP callout by setting request hearder as :-

 

  request.setHeader('Content-Type','multipart/form-data;boundary="===============123456==";'); ?

 

Currently I am getting error , and I have not found any salesforce documentation stating that multipart/form-data is not supported.

almazanjlalmazanjl

I just finished a Salesforce integration with WatchBox. I created a Visualforce component to upload files to WatchDox. It is multiuploader, can upload multiple files in the same process, supports drag & drop and has progress bar for each file. I have used the API version 3 of WatchDox. It also creates a record in a custom object related to an account with the uploaded file information to WatchDox.

It also creates a record in a custom object related to an account with the uploaded file information to WatchDox. You can watch a video on Youtube with my component in action for browsers that support HTML5. This component also works with browsers that do not support HTML5, but loses some functionality.

The key to everything is to use "Content-Transfer-Encoding: base64 '.