I'm developing in JS, React on the frontend, and Node, Express on the backend.
I have a call button that I press that I want to start an outgoing call via Twilio. I've got a Node server with a couple endpoints, one to generate a token and the other is the voice url.
On the frontend, I'm making a Twilio.Device
and have it logging when it's ready. I click on the button, that hit's Twilio's example SDK function that calls Twilio.Device.connect()
and I am passing {number: n}
into it.
On the backend, the request is made and the voice url is hit, but without a body. When I try logging req.body
, it's just an empty object.
When I try hitting the Node server directly from Postman, with the same body ({number: '+11231231122'}
) I see everything in the log.
Something is happening between the front and backends, but I cannot figure out what it is.
Twilio developer evangelist here.
Twilio will be sending the body, but as you are using Express it is likely that you aren't parsing that body properly.
Twilio sends requests as url encoded parameters, so you need to use body-parser to parse the body into req.body
within a request. Try setting your app like so:
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.urlencoded({ extended: false }));