cancel
Showing results for 
Search instead for 
Did you mean: 

XSJS Outbound API - Post Request (Twilio SMS API)

irfan_gokak
Contributor
0 Kudos

Dears,

I'm trying to send SMS using Twilio SMS API from Hana XSJS. I have tested GET request from API, it's working as expected. But when I'm trying for POST, response code 301 MOVED PERMANENTLY. Below are the details.

@Thomas.jung , Need your help here.

User-Provided Instance

twilio.xsjs

var dest = $.net.http.readDestination("EXTERNAL_HTTP");

var client = new $.net.http.Client();
var req = new $.net.http.Request($.net.http.POST,"/Messages.json");

req.headers.set("Accept" , "application/json");
req.headers.set("Content-Type" , "application/x-www-form-urlencoded");
req.setBody("To=%2B919591439099&From=%2B12565619707&Body=+%0AJob");
client.request(req, dest);
console.log(req);
$.response.setBody(client.getResponse());

EXTERNAL_HTTP.xshttpdest

host = "api.twilio.com";
port = 443;
pathPrefix = "/2010-04-01/Accounts/<account_sid>";
proxyType = "http";
proxyHost = "proxy";
proxyPort = 8080;
authType = basic;
useSSL = false;
timeout = 0;
sslAuth = "anonymous";

Postman

Thanks in Advance.

Regards,

Irfan G.

irfan_gokak
Contributor
0 Kudos

thomas.jung , please help.

View Entire Topic
pfefferf
Active Contributor
0 Kudos

You are getting a redirect (301) response because you are calling the HTTP endpoint of Twilio. You have to use the HTTPS endpoint.

irfan_gokak
Contributor
0 Kudos

Hi Florian,

Thanks for response.

Yes I understood that. But I'm not getting where I should maintain it. In destination?

Regards,

Irfan G.

pfefferf
Active Contributor
0 Kudos

In your xshttpdest file set useSSL to true. And of course your HANA system must be configured to support secured outbound connections.

irfan_gokak
Contributor
0 Kudos

Dear Florian,

Thanks for sharing info. Actually I'm beginner in xsjs. And I'm doing this development in SCP Cloud Foundry - Hana Cloud DB. So if you can share any documents how to configure secured outbound connections in CLF space that will be very helpful.

Thanks.