Debug Twilio Function

85 views
Skip to first unread message

Kanwal Preet Singh

unread,
Feb 27, 2018, 8:00:46 AM2/27/18
to Twilio Functions
Could anyone help me in debugging the twilio functions ? I am not able access the api exposed by AWS API Gateway in an twilio function.

Chris Corcoran

unread,
Feb 27, 2018, 2:59:58 PM2/27/18
to Twilio Functions
Hi Kanwal,

Thanks for your interest in Twilio Functions, I'd be happy to help. Can you provide some more details on what you're trying to do? Ideally, if you have some sample code to share that would be really helpful.

Thanks,
Chris Corcoran
Product Manager, Twilio Runtime

Kanwal Preet Singh

unread,
Mar 1, 2018, 2:09:33 AM3/1/18
to Twilio Functions
Hi Chris,

My requirement is to access third party API inside a twilio function and pass the result string from the API as a response in twilio. I had tried using got module for this, but was able to send a request to the API using the https module in the function. Now, the request is successfully send to my API as shown in my API logs and also the status of the response in twilio function is 200(as required). The issue is taht I am unable to get the JSON data passed along the response in twilio. Please find below a sample code for reference -

let options = {
        host: hostname,
        port: '443',
        path: api+querystring,
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
        }
    };

    let req = https.request(options, (res)=> { //-----Working Properly----Status 200--------//
        res.on('data', (d)=> {
          console.log(d); //-----Not getting the required data-----//
          //twiml.message(d.data);
            callback(null, twiml);
        });
    });

Chris Corcoran

unread,
Mar 4, 2018, 5:02:29 PM3/4/18
to Twilio Functions
Hi Kanwal,

I took a look at your code, nothing is sticking out as obviously wrong. There is also nothing in the Functions environment that would interfere with a JSON response from a third-party API.

This seems like an issue with the HTTP client you are using. Its not obvious from the code sample you provided which library you're using. Can you share which module you're using to make your HTTP request?

Thanks,
Chris
Reply all
Reply to author
Forward
0 new messages