Integrating with Twilio

28 views
Skip to first unread message

Rob Wilkerson

unread,
Sep 22, 2015, 9:01:01 AM9/22/15
to restify
Hey, guys -

I'm attempting to integrate my API with Twilio such that I can send a SMS to Twilio and get an SMS in return. To do that, Twilio sends a HTTP request to an endpoint where I generate a formatted response that it understands. What I'm finding is that, by the time a Twilio request hits the API, the `request.body` is undefined.

In every other way, the API is and has been running just fine, but it always returns a 400 in response to a Twilio request. I've been messing with this for a couple of days now and I _think_ I've tracked it down to the fact that Twilio's request is sent with a `Content-Type: application/x-www-form-urlencoded` header. 

This content type is not in the server.acceptable array that I pass to restify.acceptParser() and simply pushing that value onto the acceptable array changes nothing (not entirely unexpected).

I guess my question is simply this:

What, if anything, can I do to get Restify to understand, parse and properly handle an incoming request with this content-type?

Thanks.

Mario Pareja

unread,
Sep 24, 2015, 8:36:20 PM9/24/15
to restify
Rob,

Have you looked at the Restify body parser middleware? http://mcavage.me/node-restify/#bundled-plugins

It should parse form encoded POST requests.

Hope that helps or at least sets you in the right path,


Mario Pareja

Rob Wilkerson

unread,
Sep 25, 2015, 10:05:26 AM9/25/15
to restify
Thanks, Mario - 

In my case, I had a stray version identifier in there that I was so used to seeing that I didn't even notice. Since Twilio knows nothing about my API (other than it's endpoint url), it sends no version and Restify found no matching route. Once I remove the version, the API connected nicely.

Thanks for the reply. If nothing else, it reminded me that I needed to update the question with its answer for any future searchers.
Reply all
Reply to author
Forward
0 new messages