List<ContentVersion> cvList = [SELECT VersionData, Title FROM ContentVersion WHERE Id = '068OD00000137hmYAA'];
String boundary = '----WebKitFormBoundary' + String.valueOf(Crypto.getRandomLong());
String requestUrl = 'https://api.in1.adobesign.com:443/api/rest/v6/transientDocuments';
String header = '--' + boundary + '\r\n' + 'Content-Disposition: form-data; name="File"; filename="{0}"\r\nMime-Type: {1}\r\n\r\n';
String footer = '\r\n--' + boundary + '--\r\n';
List<String> parts = new List<String>();
for (ContentVersion thisVersion : cvList) {
String contentType = 'application/pdf'; // Replace with the correct content type based on the file type
String part = String.format(header, new String[]{thisVersion.Title, contentType}) + EncodingUtil.base64Encode(thisVersion.VersionData).replaceAll('[/+]', '_').replaceAll('[-]', '/') + footer; //thisVersion.VersionData + footer; //
parts.add(part);
}
String requestBody = String.join(parts, '');
Blob requestBlob = Blob.valueOf(requestBody);
HttpRequest request = new HttpRequest();
request.setEndpoint(requestUrl);
request.setMethod('POST');
request.setHeader('Authorization','Bearer '+accessToken);
request.setHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
request.setBodyAsBlob(requestBlob);
Http http = new Http();
HttpResponse response = http.send(request);
system.debug('Transient Document==>'+response.getBody());
if(response.getStatusCode()==200){
String responseBody = response.getBody();
system.debug(VA_TransientDocumentJSONWrapper.parse(responseBody));
VA_TransientDocumentJSONWrapper wrapper = VA_TransientDocumentJSONWrapper.parse(responseBody);
system.debug('wrapper'+wrapper.transientDocumentId);
return wrapper.transientDocumentId;
}
I'm able to get the transient documentId as a response and agreement is also generated and email is received for e-signature. However, attached pdf in the email is base64 encoded and does not show the actual PDF. Kindly let me know what I'm missing. Need urgent help.!!