I am trying to create transient document in adobe sign using rest api. After lot of research I was able to make the correct multi form request in Salesforce Apex.But now I am getting the file content missing error when I checked the debug log in adobe sign Account. Below is my code snippet:

 String boundary = '----------------------------741e90d31eff';
      String header = '--'+boundary+'\nContent-Disposition: form-data; name="file"; filename="testsign.pdf";\nContent-Type: application/octet-stream';

  String footer = '--'+boundary+'--';             
  String headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\r\n\r\n'));
     header+=' ';
     headerEncoded = EncodingUtil.base64Encode(Blob.valueOf(header+'\r\n\r\n'));
    Blob testFileContent = Blob.valueOf('test file is sdfsdfsfs');
 // Blob testFileContent =[SELECT VersionData FROM ContentVersion WHERE ContentDocumentId = '0690x000001OhAu'][0].VersionData;
  String bodyEncoded = EncodingUtil.base64Encode(testFileContent);

  Blob bodyBlob = null;
  String last4Bytes = bodyEncoded.substring(bodyEncoded.length()-4,bodyEncoded.length());

 if(last4Bytes.endsWith('==')) {
    system.debug('inside first');
    last4Bytes = last4Bytes.substring(0,2) + '0K';
    bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes;

    String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
    bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);
  } else if(last4Bytes.endsWith('=')) {
    system.debug('inside second');
    last4Bytes = last4Bytes.substring(0,3) + 'N';
    bodyEncoded = bodyEncoded.substring(0,bodyEncoded.length()-4) + last4Bytes;

    footer = '\n' + footer;
    String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
    bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);              
  } else {
    system.debug('inside third');
    footer = '\r\n' + footer;
    String footerEncoded = EncodingUtil.base64Encode(Blob.valueOf(footer));
    bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded+footerEncoded);  
  HttpRequest req = new HttpRequest();
  String authorizationHeader = 'Bearer ' +acceessToken;
  req.setHeader('Authorization', authorizationHeader);
  req.setHeader('Content-Type','multipart/form-data; boundary='+boundary);

  Http http = new Http();

        HTTPResponse res = http.send(req);

And following is response from adobe sign:

x-request-id : ecca058a-02b7-4dfe-8e9a-a64869798407
content-type : application/json
status : 400

     "code": "NO_FILE_CONTENT",
     "message": "Must provide file body"

Please anyone if have face same issue do help me wiht it what i am missing out here.


One thing to try, looking at https://secure.na1.echosign.com/public/docs/restapi/v6#!/transientDocuments/createTransientDocument

The parameter name is "File" not "file", HTTP parameters can be case sensitive. Try changing name="file" to name="File" in line 2.


I tried with vNHttpFormBuilder class also but it was giving as "bad request:file content missing error"

After some efforts,I concluded the request have to be key-value pair format. So I have tired below solution, it is working fine now, but the only issue is that I have to convert the content of vf page into string and send the data.

 PageReference ref = page.Account_Details;
        // test
        HttpRequest req = new HttpRequest();

    // Set method and endpoint  

    // Set body
    String boundary = '----------------------------' + String.valueOf(DateTime.now().getTime());
    String body = '--' + boundary + '\r\n';
    body += 'Content-Disposition: form-data; name="File-Name"\r\n\n';
    body += 'test.pdf\r\n';
    body += '--' + boundary + '\r\n';
    body += 'Content-Disposition: form-data; name="Mime-Type"\r\n\n';
    body += 'text/html\r\n';
    body += '--' + boundary + '\r\n';
    body += 'Content-Disposition: form-data; name="File"\r\n\n';
    body += ref.getContent().toString()+'\r\n';
    body += '--' + boundary + '--';
  //  Blob bodyBlob = EncodingUtil.base64Decode(body);
  //  req.setBodyAsBlob(bodyBlob);
    // Set headers
    req.setHeader('Content-Type', 'multipart/form-data; boundary='+boundary);
    //req.setHeader('Content-Length', String.valueof(body.length()));
    req.setHeader('Authorization','Bearer ' +IntegrationKey);
    system.debug('req: ' + req);
    system.debug('req.header.contenttype: ' + req.getHeader('Content-Type'));
    system.debug('req.header.contentlength: ' + req.getHeader('Content-Length'));
    system.debug('req.body: ' + req.getBody());

    // Send HTTP request and get HTTP response
    Http http = new Http();

        HttpResponse res = http.send(req);
        system.debug('res: ' + res.getBody());
        System.debug('transient document = : '+res.getStatusCode() + 'status'+res.getStatus());  
        if(res.getStatus() == 'OK' && res.getStatusCode() == 200){
            AdobeSignWrapperClass adobeWrap = AdobeSignWrapperClass.parseJson(res.getBody());
                transientDocumentId = adobeWrap.transientDocumentId;

    catch(Exception e){   
        system.debug('error is'+e);
    return agreementId;

However, what we want over here is we want to send the pdf version of VF page or a contentversion of pdf. So in place of

body += ref.getContent().toString()+'\r\n';

if we use

body += ref.getContentasPDF();

and instead of

body += 'text/html\r\n';

we use :

body += 'application/pdf\r\n';

the document is not being sent over there properly and it is showing bad content error.

  • To me it seems that you would still need to base64Encode(ref.getContentasPDF()), and then have some type of solution in place that safely pads the data like you previously had. – Craig Johnson Nov 2 '19 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.