cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in calling POST Service form XSJS

Former Member
0 Kudos

Hello All,
I'm trying to call a POST REST API from my xsjs service but I'm getting the following error - HttpClient.getResponse: Can't get the response from the server: no response is pending...you have to issue a request() first

Given below is my destination and xsjs file

http_dest

host = "https://l5471-iflmap.hcisbp.us2.hana.ondemand.com"; pathPrefix = "/http"; port = 467; proxyType = http; proxyHost = "proxy"; proxyPort = 8080; authType = basic; useSSL = false; sslHostCheck = false;

Test.xsjs

try{ var destination; var client;

destination = $.net.http.readDestination("DFT.RulesProject","http_dest");

client = new $.net.http.Client();

var request = new $.net.http.Request($.net.http.POST,"/commonemail");

request.headers.set("Content-Type" , "application/json");

request.headers.set("Accept" , "application/json");

request.setBody(JSON.stringify( { "mailParam":{ "emailBody": "emailBody", "emailSubject": "emailSubject", "to": "shubham.apatidar@incture.com" }}));

client.request(request, destination);

$.response.setBody(JSON.stringify( {

"Success": client.getResponse().status, "Code" : client.getResponse() } ));

}

catch(e){ $.response.status = $.net.http.INTERNAL_SERVER_ERROR; $.response.setBody(e.message ); }

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate

In your host you have HTTPS://. You shouldn't put the protocol there but only the hostname. Also if you have https really as part of the target then why do you have useSSL = false?

Former Member
0 Kudos

Hello Thomas,

I've changed useSSL= true, imported the certificate, changed the port to 433 and removed the HTTPS:// from hostname. Still I'm getting the below error-

HttpClient.getResponse: Can't get the response from the server: no response is pending...you have to issue a request() first

thomas_jung
Developer Advocate
Developer Advocate

Perhaps the problem is that you are calling getResponse twice:

client.getResponse().status, "Code" : client.getResponse()

I always call this once and put the return object into a variable. Then get the status and body from it.

Former Member
0 Kudos

Thanks, Thomas.

I'm getting status 401 now.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

That's progress. I don't see any authentication information in your destination and 401 is unauthorized, so I guess you know where to look next.

Former Member
0 Kudos

I've given all the authentication credentials in XS Admin and have imported the SSL certificate but still I', facing these issue.

rajiv_kanoria
Explorer
0 Kudos

Hi All,

What if in case we are calling an API hosted on Cloud Foundry. What should be the post we need to configure in Destination in xsjs?

Regards,

Rajiv

Answers (0)