Making SIP Calls
Use Twilio's REST API to connect to your SIP-enabled endpoints. With this feature, you can set up a VoIP session using SIP. If you are unfamiliar with SIP, or want more information on how Twilio works with your SIP endpoint, please see the SIP overview.
Initiate SIP sessions via the REST API by POST
ing to the same calls resource used to initiate traditional phone calls (see making calls for more information). Once the call is connected, Twilio will then fetch the TwiML you specify for the call. For example, make a SIP call by POST
ing to your account's calls list resource URI:
_10 /2010-04-01/Accounts/{AccountSid}/Calls
All outgoing call features and parameters are supported — the only difference is that you pass different values in the "To" and "From" parameters. In the "To" parameter, put the SIP URI you are trying to connect to. In the "From" parameter, specify the user you want to show up in the From header in the SIP request.
You must POST
the following parameters:
Parameter | Description |
---|
To | The SIP URI to which you want to connect |
The 'To' parameter specifies a SIP address for Twilio to connect to. The body of the URI element should be a valid SIP URI under 255 characters. For example:
_10sip:michael@example.com
Set a parameter on your SIP URI to specify what transport protocol you want to use. You may use UDP
, TCP
or TLS
. By default, Twilio sends your SIP INVITE over UDP
. Change this by using the transport parameter:
_10sip:jack@example.com;transport=tcp
Also, when using transport=tls
, this will only encrypt SIP signaling messages and not RTP
. To use SRTP
and to encrypt SIP signaling, please add a parameter secure=true
to your SIP URI:
_10sip:jack@example.com;secure=true
You may POST
the following parameters:
Parameter | Description |
---|
From | This value is used to populate the username portion of the From header that is passed to the SIP endpoint. This may be any alphanumeric character, as well as the plus, minus, underscore, and period characters (+-_.). No spaces or other characters are allowed. |
SipAuthUsername | Your authentication username. |
SipAuthPassword | The password for the user. |
Basic SIP dial using the REST API.
_20// Download the helper library from https://www.twilio.com/docs/node/install
_20const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20// Find your Account SID and Auth Token at twilio.com/console
_20// and set the environment variables. See http://twil.io/secure
_20const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20const authToken = process.env.TWILIO_AUTH_TOKEN;
_20const client = twilio(accountSid, authToken);
_20async function createCall() {
_20 const call = await client.calls.create({
_20 to: "sip:kate@example.com",
_20 url: "http://www.example.com/sipdial.xml",
_20 console.log(call.sid);
_39 "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39 "api_version": "2010-04-01",
_39 "date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
_39 "date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
_39 "direction": "inbound",
_39 "end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
_39 "forwarded_from": "+141586753093",
_39 "from_formatted": "(415) 867-5308",
_39 "parent_call_sid": null,
_39 "phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39 "sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39 "start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
_39 "status": "completed",
_39 "subresource_uris": {
_39 "notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
_39 "recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
_39 "payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
_39 "events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
_39 "siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
_39 "streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
_39 "transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
_39 "user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
_39 "user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
_39 "to": "sip:kate@example.com",
_39 "to_formatted": "(415) 867-5309",
_39 "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
Pass user and password to your SIP call for authentication.
_22// Download the helper library from https://www.twilio.com/docs/node/install
_22const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_22// Find your Account SID and Auth Token at twilio.com/console
_22// and set the environment variables. See http://twil.io/secure
_22const accountSid = process.env.TWILIO_ACCOUNT_SID;
_22const authToken = process.env.TWILIO_AUTH_TOKEN;
_22const client = twilio(accountSid, authToken);
_22async function createCall() {
_22 const call = await client.calls.create({
_22 sipAuthPassword: "secret",
_22 sipAuthUsername: "jack",
_22 to: "sip:kate@example.com",
_22 url: "http://www.example.com/sipdial.xml",
_22 console.log(call.sid);
_39 "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39 "api_version": "2010-04-01",
_39 "date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
_39 "date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
_39 "direction": "inbound",
_39 "end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
_39 "forwarded_from": "+141586753093",
_39 "from_formatted": "(415) 867-5308",
_39 "parent_call_sid": null,
_39 "phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39 "sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39 "start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
_39 "status": "completed",
_39 "subresource_uris": {
_39 "notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
_39 "recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
_39 "payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
_39 "events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
_39 "siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
_39 "streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
_39 "transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
_39 "user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
_39 "user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
_39 "to": "sip:kate@example.com",
_39 "to_formatted": "(415) 867-5309",
_39 "uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",