• azrkhn
  • NEWBIE
  • 5 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hello,

I am calling a remote webservice api from apex.

This is how the request should look like as per the api documentation.
URL: 'https://example.com/merge'
Method: 'POST'
Content-Type: 'multipart/form-data'
Parameters: {file_1: 'BINARY_PDF_DATA', file_2: 'BINARY_PDF_DATA', file_3: ..., user: 'auth_username', password: 'auth_password'}
Result: 'BINARY_PDF_DATA'

Below is the code that I have accomplished so far, but the problem is that this code returns a 500 - Internal Server Error when I run it.

Here is my code:
string username = 'auth_username';
string password = 'auth_password';
boolean isTest = true;
								

 Http h = new Http();
 HttpRequest req = new HttpRequest();
 req.setEndpoint('https://example.com/merge');
 req.setMethod('POST');
 req.setHeader('Content-Type','multipart/form-data; boundary=----RandomString');
                                                                
 string body = '------RandomString\r\n';
 body += 'Content-Disposition: form-data;';
body += 'name=\"user\"\r\n\r\n'+username+'\r\n';
                                
body += '------RandomString\r\n';
body += 'Content-Disposition: form-data;';
body += 'name=\"password\"\r\n\r\n'+password+'\r\n';
                                
body += '------RandomString\r\n';
body += 'Content-Disposition: form-data;';
body += 'name=\"test\"\r\n\r\n'+isTest+'\r\n';
                                
 // build the blob form data
                                
 integer k = 1;
for(blob blb : blobs){
                                    
body += '------RandomString\r\n';
body += 'Content-Disposition: form-data; name="file_'+k+'"; filename="file_'+k+'.pdf"\r\n\r\n';
body+= EncodingUtil.base64Encode(blb) +'\r\n';

k++;

}
                                
body += '------RandomString--';
req.setBody(body);
                                
 // Send the request, and return a response
HttpResponse res = h.send(req);

system.debug('Response is: ');
system.debug(res);

So I could not figure out what is wrong as apparently I have meet the webservice callout requirments as mentioned in the api documentation.

Any help in this regard will be appreciated.
Hello,

I am calling a remote webservice api from apex.

This is how the request should look like as per the api documentation.
URL: 'https://example.com/merge'
Method: 'POST'
Content-Type: 'multipart/form-data'
Parameters: {file_1: 'BINARY_PDF_DATA', file_2: 'BINARY_PDF_DATA', file_3: ..., user: 'auth_username', password: 'auth_password'}
Result: 'BINARY_PDF_DATA'

Below is the code that I have accomplished so far, but the problem is that this code returns a 500 - Internal Server Error when I run it.

Here is my code:
string username = 'auth_username';
string password = 'auth_password';
boolean isTest = true;
								

 Http h = new Http();
 HttpRequest req = new HttpRequest();
 req.setEndpoint('https://example.com/merge');
 req.setMethod('POST');
 req.setHeader('Content-Type','multipart/form-data; boundary=----RandomString');
                                                                
 string body = '------RandomString\r\n';
 body += 'Content-Disposition: form-data;';
body += 'name=\"user\"\r\n\r\n'+username+'\r\n';
                                
body += '------RandomString\r\n';
body += 'Content-Disposition: form-data;';
body += 'name=\"password\"\r\n\r\n'+password+'\r\n';
                                
body += '------RandomString\r\n';
body += 'Content-Disposition: form-data;';
body += 'name=\"test\"\r\n\r\n'+isTest+'\r\n';
                                
 // build the blob form data
                                
 integer k = 1;
for(blob blb : blobs){
                                    
body += '------RandomString\r\n';
body += 'Content-Disposition: form-data; name="file_'+k+'"; filename="file_'+k+'.pdf"\r\n\r\n';
body+= EncodingUtil.base64Encode(blb) +'\r\n';

k++;

}
                                
body += '------RandomString--';
req.setBody(body);
                                
 // Send the request, and return a response
HttpResponse res = h.send(req);

system.debug('Response is: ');
system.debug(res);

So I could not figure out what is wrong as apparently I have meet the webservice callout requirments as mentioned in the api documentation.

Any help in this regard will be appreciated.
can anyone help me solving the Second step for Lightning Component Framework Specialist super badge.. I struck in that badge.