You need to sign in to do that
Don't have an account?
GAURAV SETH
External Web Service Call from Apex Class-Certificate Issue
I need to call a external web service from Apex class.
I am always getting unsuccessful response.
If I hit that url from Postman, I am getting response successfully.
I took the jSessionId LTPAToken2 from Postman response and add it to my Apex class as below:
request.setHeader('Cookie', 'JSESSIONID=0000huO7wL9GJGO_ZEAlW-4NDCd:-1; LtpaToken2=ZLjH0oX2UiZfYXakvwH5+AhhhCYaEIEEoBCsD12bHY+Ovs+4VF5zFo0B00gMDNjQMwcA==')
After this when I execute my Apex class, I am getting successful response. I am wondering that there migh tbe certificate issue .
Can someone please help ?
I am always getting unsuccessful response.
If I hit that url from Postman, I am getting response successfully.
I took the jSessionId LTPAToken2 from Postman response and add it to my Apex class as below:
request.setHeader('Cookie', 'JSESSIONID=0000huO7wL9GJGO_ZEAlW-4NDCd:-1; LtpaToken2=ZLjH0oX2UiZfYXakvwH5+AhhhCYaEIEEoBCsD12bHY+Ovs+4VF5zFo0B00gMDNjQMwcA==')
After this when I execute my Apex class, I am getting successful response. I am wondering that there migh tbe certificate issue .
Can someone please help ?
Can you please tell us how you are building your HTTP object? It is hard to say what mistake you are doing from this line.
Thanks
Ayush
Here is the code used by me :
Http http = new Http();
HttpRequest request = new HttpRequest();
String intake_Id = intakeId[0];
String EndPoint = 'https://URL:port/Rest/v1/cwa/intakes?investigation_id='+intake_Id;
request.setEndpoint(EndPoint);
request.setMethod('GET');
HttpResponse response = http.send(request);
Thanks,
Gaurav Seth
I can't see any Authorization header in your given HTTP object.
As I can see '0000huO7wL9GJGO_ZEAlW-4NDCd:-1; LtpaToken2=ZLjH0oX2UiZfYXakvwH5+AhhhCYaEIEEoBCsD12bHY+Ovs+4VF5zFo0B00gMDNjQMwcA==' is a base64. So if you have any Secret or API key which you use, to authorize to the server then convert them into Base64 and use it inside your authorization header.
If answer is not relative then please share the API documentation from where you have taken reference.
Thanks
Ayush
string username = 'user';
string password = 'password';
request.setTimeout(120000);
// Add basic authentication to header
// Create blob of user:pass
Blob headerValue = Blob.valueOf(username + ':' + password);
// Base 64 Encode the blob and prepend "Basic "
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
// Add the basic auth string to the Request Header
request.setHeader('Authorization', authorizationHeader);
I have that external web service entry in Remote Site Settings too. Anything else needs to be done?
Thanks,
Gaurav Seth