Skip to contentSkip to navigationSkip to topbar
On this page

Making Calls


Using the Twilio REST API, you can make outgoing calls to phones, SIP-enabled endpoints, and Twilio Voice SDK connections.

(information)

Info

Looking for the API Reference docs? Check out the full API reference for Calls.

In this guide, we'll explore how you can use Twilio's Programmable Voice API to:

(information)

Info

Prefer a step-by-step guide to making your first call? Check out our Programmable Voice quickstart in C#, Java, Node.js, PHP, Python, Ruby, or Go.


Initiate an outbound call with Twilio

initiate-an-outbound-call-with-twilio page anchor

To place an outbound call, a phone call from a Twilio phone number to an outside number, you must make an HTTP POST request to your account's Call resource:

/2010-04-01/Accounts/{AccountSid}/Calls
(warning)

Warning

Calls initiated via the REST API are rate-limited to one per second. You can queue up as many calls as you like as fast as you want, but each call is popped off the queue at a rate of one per second.

Your POST request to the API must include the parameters From and To for Twilio to know where to direct the outbound call and what to use as the caller ID.

Specify the call's recipient

specify-the-calls-recipient page anchor

The To parameter (required) is the phone number, SIP address, or client identifier you're calling.

Phone numbers should be formatted with a '+' and country code e.g., +16175551212 (E.164(link takes you to an external page) format).

(warning)

Warning

If you are making calls from a trial account, the To phone number must be verified with Twilio. You can verify your phone number by adding it to your Verified Caller IDs(link takes you to an external page) in the console.

SIP addresses must be formatted as sip:name@example.com. For example, to dial Pat's SIP address at Example Company, the To parameter should be sip:pat@example.com.

Client identifiers must begin with theclient:URI scheme. For example, to call a client named joey, the To parameter should be client:joey.

Twilio uses the From parameter (required) to set a phone number or client identifier as the caller ID for your outbound call.

If you used a phone number for your To value in your POST request, the From value you specify must also be a phone number. Just as with the To parameter, phone numbers should be formatted with a '+' and country code, e.g., +16175551212 (E.164(link takes you to an external page) format).

Any phone number you specify here must be a Twilio phone number (you can purchase a number through the console(link takes you to an external page)) or a verified outgoing caller id for your account.

If you use a client identifier as the value for From, your identifier must begin with the client:URI scheme. For example, to set a client named charlie as your caller ID, your From parameter should be client:charlie.

Tell Twilio what to do on the call

tell-twilio-what-to-do-on-the-call page anchor

When you initiate an outbound call with the Twilio REST API, Twilio needs to access your instructions for how to handle the call. It does this by making a synchronous HTTP request to either:

  1. a URL that hosts a set of TwiML instructions (this could be an XML document or web application) or
  2. the set of URLs and configuration you've created as an application in the Twilio console(link takes you to an external page)

Specify a URL parameter

specify-a-url-parameter page anchor

If you specify a URL parameter in your request, Twilio will make its HTTP request to this URL to retrieve TwiML to handle the call. This request from Twilio is identical to the request Twilio sends when receiving an inbound call.

(warning)

Warning

URLs must contain a valid hostname, and underscores are not permitted.

The following examples show how to create an outbound call to a phone number, a Twilio Voice SDK device, and a SIP address with the REST API.

In all three examples, Twilio will POST to http://demo.twilio.com/docs/voice.xml to fetch TwiML for handling the call.

Make an outbound call to a phone numberLink to code sample: Make an outbound call to a phone number
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createCall() {
11
const call = await client.calls.create({
12
from: "+15017122661",
13
to: "+14155551212",
14
url: "http://demo.twilio.com/docs/voice.xml",
15
});
16
17
console.log(call.sid);
18
}
19
20
createCall();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"annotation": null,
4
"answered_by": null,
5
"api_version": "2010-04-01",
6
"caller_name": null,
7
"date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
8
"date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
9
"direction": "inbound",
10
"duration": "15",
11
"end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
12
"forwarded_from": "+141586753093",
13
"from": "+15017122661",
14
"from_formatted": "(415) 867-5308",
15
"group_sid": null,
16
"parent_call_sid": null,
17
"phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"price": "-0.03000",
19
"price_unit": "USD",
20
"sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
22
"status": "completed",
23
"subresource_uris": {
24
"notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
25
"recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
26
"payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
27
"events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
28
"siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
29
"streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
30
"transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
31
"user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
32
"user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
33
},
34
"to": "+14155551212",
35
"to_formatted": "(415) 867-5309",
36
"trunk_sid": null,
37
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
38
"queue_time": "1000"
39
}
Make an outbound call to a Twilio Voice SDK deviceLink to code sample: Make an outbound call to a Twilio Voice SDK device
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createCall() {
11
const call = await client.calls.create({
12
from: "+15017122661",
13
to: "client:charlie",
14
url: "http://demo.twilio.com/docs/voice.xml",
15
});
16
17
console.log(call.sid);
18
}
19
20
createCall();

Output

1
{
2
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"annotation": null,
4
"answered_by": null,
5
"api_version": "2010-04-01",
6
"caller_name": null,
7
"date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
8
"date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
9
"direction": "inbound",
10
"duration": "15",
11
"end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
12
"forwarded_from": "+141586753093",
13
"from": "+15017122661",
14
"from_formatted": "(415) 867-5308",
15
"group_sid": null,
16
"parent_call_sid": null,
17
"phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"price": "-0.03000",
19
"price_unit": "USD",
20
"sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
22
"status": "completed",
23
"subresource_uris": {
24
"notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
25
"recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
26
"payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
27
"events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
28
"siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
29
"streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
30
"transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
31
"user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
32
"user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
33
},
34
"to": "client:charlie",
35
"to_formatted": "(415) 867-5309",
36
"trunk_sid": null,
37
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
38
"queue_time": "1000"
39
}
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createCall() {
11
const call = await client.calls.create({
12
from: "Jack",
13
to: "sip:kate@example.com?hatchkey=4815162342",
14
url: "http://www.example.com/sipdial.xml",
15
});
16
17
console.log(call.sid);
18
}
19
20
createCall();

Output

1
{
2
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"annotation": null,
4
"answered_by": null,
5
"api_version": "2010-04-01",
6
"caller_name": null,
7
"date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
8
"date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
9
"direction": "inbound",
10
"duration": "15",
11
"end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
12
"forwarded_from": "+141586753093",
13
"from": "Jack",
14
"from_formatted": "(415) 867-5308",
15
"group_sid": null,
16
"parent_call_sid": null,
17
"phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"price": "-0.03000",
19
"price_unit": "USD",
20
"sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
22
"status": "completed",
23
"subresource_uris": {
24
"notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
25
"recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
26
"payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
27
"events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
28
"siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
29
"streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
30
"transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
31
"user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
32
"user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
33
},
34
"to": "sip:kate@example.com?hatchkey=4815162342",
35
"to_formatted": "(415) 867-5309",
36
"trunk_sid": null,
37
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
38
"queue_time": "1000"
39
}

Specify an ApplicationSid parameter

specify-an-applicationsid-parameter page anchor

If you instead specify an ApplicationSid parameter in your POST request, Twilio will use all of the URLs and other configuration information from that application to handle the outbound call.

(warning)

Warning

Using an ApplicationSid in your request will cause Twilio to ignore the following parameters, even if you include them in your POST: Url, Method, FallbackUrl, FallbackMethod, StatusCallback, and StatusCallbackMethod. Twilio expects that your application code will handle all of this information.

You can create and configure applications in the TwiML Apps section(link takes you to an external page) of the console. Since an application contains all of the information required to handle a phone call, it makes sense to use applications to handle outbound calls with complicated call flows.

When your outbound call is connected, Twilio will make a request to the VoiceUrl set on your application. This request is identical to the request Twilio would have sent to the Url parameter, as detailed above.


Manage your outbound call

manage-your-outbound-call page anchor

When POSTing to the REST API's Calls list endpoint, you may wish to tell Twilio to take specific actions on your outbound call by sending additional parameters in your request. These could include (but are not limited to) waiting a certain amount of time for an answer, dialing an extension, or recording a call.

(information)

Info

For the full list of parameters you can pass in your POST request, check out the detailed API reference documentation for creating a Call resource.

For example, if you wish to make an outbound call and send digits in order to dial an extension, you would add the optional SendDigits parameter to your request.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createCall() {
11
const call = await client.calls.create({
12
from: "+18668675310",
13
method: "GET",
14
sendDigits: "1234#",
15
to: "+14155551212",
16
url: "http://demo.twilio.com/docs/voice.xml",
17
});
18
19
console.log(call.sid);
20
}
21
22
createCall();

Output

1
{
2
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"annotation": null,
4
"answered_by": null,
5
"api_version": "2010-04-01",
6
"caller_name": null,
7
"date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
8
"date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
9
"direction": "inbound",
10
"duration": "15",
11
"end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
12
"forwarded_from": "+141586753093",
13
"from": "+18668675310",
14
"from_formatted": "(415) 867-5308",
15
"group_sid": null,
16
"parent_call_sid": null,
17
"phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"price": "-0.03000",
19
"price_unit": "USD",
20
"sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
22
"status": "completed",
23
"subresource_uris": {
24
"notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
25
"recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
26
"payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
27
"events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
28
"siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
29
"streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
30
"transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
31
"user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
32
"user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
33
},
34
"to": "+14155551212",
35
"to_formatted": "(415) 867-5309",
36
"trunk_sid": null,
37
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
38
"queue_time": "1000"
39
}

To tell Twilio to record an outbound call, include the optional parameter Record and set its value to true:

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createCall() {
11
const call = await client.calls.create({
12
from: "+15017122661",
13
record: true,
14
to: "+14155551212",
15
url: "http://demo.twilio.com/docs/voice.xml",
16
});
17
18
console.log(call.sid);
19
}
20
21
createCall();

Output

1
{
2
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"annotation": null,
4
"answered_by": null,
5
"api_version": "2010-04-01",
6
"caller_name": null,
7
"date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
8
"date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
9
"direction": "inbound",
10
"duration": "15",
11
"end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
12
"forwarded_from": "+141586753093",
13
"from": "+15017122661",
14
"from_formatted": "(415) 867-5308",
15
"group_sid": null,
16
"parent_call_sid": null,
17
"phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"price": "-0.03000",
19
"price_unit": "USD",
20
"sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
22
"status": "completed",
23
"subresource_uris": {
24
"notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
25
"recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
26
"payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
27
"events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
28
"siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
29
"streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
30
"transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
31
"user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
32
"user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
33
},
34
"to": "+14155551212",
35
"to_formatted": "(415) 867-5309",
36
"trunk_sid": null,
37
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
38
"queue_time": "1000"
39
}

With this code, Twilio will connect the outbound call and make a recording of it. But how do you get your hands on that recording and other information about the call?


Monitor outbound call events

monitor-outbound-call-events page anchor

In the code above, we set Record=true, but we didn't give Twilio any instructions on what to do with that recording, or any other information about the call, once the call ends. Here's where the StatusCallback parameter comes into play.

Call end: setting your StatusCallback

call-end-setting-your-statuscallback page anchor

After an outbound call ends, Twilio will make an asynchronous HTTP request to the StatusCallback URL specified in your POST request. If you don't provide a URL for this parameter, Twilio will simply end the call without sending information back to you.

(warning)

Warning

Any StatusCallback URL you set must contain a valid hostname. Underscores are not permitted.

Let's update the POST request to place an outbound call, specifying a StatusCallback URL this time to tell Twilio where to send data after the call ends.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createCall() {
11
const call = await client.calls.create({
12
from: "+18668675310",
13
method: "GET",
14
statusCallback: "https://www.myapp.com/events",
15
statusCallbackMethod: "POST",
16
to: "+14155551212",
17
url: "http://demo.twilio.com/docs/voice.xml",
18
});
19
20
console.log(call.sid);
21
}
22
23
createCall();

Output

1
{
2
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"annotation": null,
4
"answered_by": null,
5
"api_version": "2010-04-01",
6
"caller_name": null,
7
"date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
8
"date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
9
"direction": "inbound",
10
"duration": "15",
11
"end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
12
"forwarded_from": "+141586753093",
13
"from": "+18668675310",
14
"from_formatted": "(415) 867-5308",
15
"group_sid": null,
16
"parent_call_sid": null,
17
"phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"price": "-0.03000",
19
"price_unit": "USD",
20
"sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
22
"status": "completed",
23
"subresource_uris": {
24
"notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
25
"recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
26
"payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
27
"events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
28
"siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
29
"streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
30
"transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
31
"user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
32
"user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
33
},
34
"to": "+14155551212",
35
"to_formatted": "(415) 867-5309",
36
"trunk_sid": null,
37
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
38
"queue_time": "1000"
39
}

Note that you can specify a StatusCallbackMethod to tell Twilio what kind of HTTP request to make to your StatusCallback URL. This is an optional parameter that defaults to POST.

When the call shown above ends, Twilio will send all of the same parameters it uses when someone places a call to one of your Twilio phone numbers. Check out the full list of parameters Twilio always sends with this request.

Get call status events during a call

get-call-status-events-during-a-call page anchor

The optional StatusCallbackEvent parameter lets you specify which call progress events Twilio will act on. You can use this parameter to tell Twilio to send information to the StatusCallback URL you specified when a call is initiated, ringing, answered, or completed:

Timeline of events and call status on an outbound call.
EventDescription
initiatedThe initiated event is fired when Twilio removes your call from the queue and starts dialing the call
ringingThe ringing event is fired when the call starts ringing
answeredThe answered event fires when someone answers the call
completedThe completed event is fired when the call ends, regardless of the termination status: busy, canceled, completed, failed, or no-answer. This means that when the call has finished execution, one of those termination statuses will be returned. If no StatusCallbackEvent is specified, completed will fire by default.

With the following code, Twilio will POST information about the outbound call when the call dequeues and starts dialing.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createCall() {
11
const call = await client.calls.create({
12
from: "+18668675310",
13
method: "GET",
14
statusCallback: "https://www.myapp.com/events",
15
statusCallbackEvent: ["initiated", "answered"],
16
statusCallbackMethod: "POST",
17
to: "+14155551212",
18
url: "http://demo.twilio.com/docs/voice.xml",
19
});
20
21
console.log(call.sid);
22
}
23
24
createCall();

Output

1
{
2
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"annotation": null,
4
"answered_by": null,
5
"api_version": "2010-04-01",
6
"caller_name": null,
7
"date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
8
"date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
9
"direction": "inbound",
10
"duration": "15",
11
"end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
12
"forwarded_from": "+141586753093",
13
"from": "+18668675310",
14
"from_formatted": "(415) 867-5308",
15
"group_sid": null,
16
"parent_call_sid": null,
17
"phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"price": "-0.03000",
19
"price_unit": "USD",
20
"sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
22
"status": "completed",
23
"subresource_uris": {
24
"notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
25
"recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
26
"payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
27
"events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
28
"siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
29
"streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
30
"transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
31
"user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
32
"user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
33
},
34
"to": "+14155551212",
35
"to_formatted": "(415) 867-5309",
36
"trunk_sid": null,
37
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
38
"queue_time": "1000"
39
}

If you leave the StatusCallbackEvent out of your request but still specify a StatusCallback URL, Twilio will default to the event to completed and send data to your URL after the call ends.

Specify a RecordingStatusCallback

specify-a-recordingstatuscallback page anchor

If you request a recording of an outbound call by specifying Record=true, you can set a RecordingStatusCallback URL so that Twilio will make a GET or POST request to your URL when the recording is available.

Twilio will send information to your specified RecordingStatusCallback URL like the CallSid, RecordingStatus, and the RecordingUrl (the URL where you can access the recording).

Check out the full list of parameters that Twilio will pass with its request to your RecordingStatusCallback URL.

(information)

Info

To pause, resume, or stop recordings programmatically, see the Recording API Docs. Or, explore our guides for recording phone calls using Twilio's helper libraries.

Just as an outbound call has a series of status events, so does the recording Twilio makes for you.

By setting the RecordingStatusCallbackEvent, you can specify which recording status changes should trigger a request to your RecordingStatusCallback URL. The RecordingStatusCallbackEvent values default to completed, but possible values are completed, absent, in-progress. To specify more than one value, separate each with a space.


Handle possible call outcomes

handle-possible-call-outcomes page anchor

After Twilio completes your outbound call, it will make a synchronous request to the URL you specified in your POST request. In this request, Twilio sends all of its standard request parameters.

From here, it's up to you what happens next! You may wish to trigger another event, like send an SMS to the To phone number you just called with a follow-up message, or try to place the call again if the CallStatus returns failed.

For step-by-step instructions on making outbound calls and receiving inbound calls, check out our Programmable Voice quickstart in one of our six supported helper library languages: C#/.NET, Java, Node.js, PHP, Python, Ruby, or Go. You can also add voice capabilities to your web application with the Voice JavaScript SDK, or leverage Twilio's mobile client SDKs for your Android or iOS applications.

You can also explore all of our Programmable Voice tutorials to learn how to modify calls in progress programmatically, record phone calls, create conference calls, and more.

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.