Learn to make and manage outbound phone calls with Twilio Programmable Voice by sending a POST request to the Calls resource in the Twilio Voice API. You can use this guide to send notifications and build outbound call centers.
To learn all of the API response values that you can return with print(), see the response for Create a call in the API documentation. Precede the response value with call. (for example: print(call.sid) returns the sid value).
Set the environment variables for your Account SID, API key SID, and API key secret.
On Mac or Linux:
Run the following commands to add your credentials as environment variables in a twilio.env file and source them. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
If you're committing code with git, run the following command to add the twilio.env file to .gitignore to avoid uploading your credentials in plain text:
echo"twilio.env">>.gitignore
On Windows command line (cmd.exe):
Run the following commands. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
Replace the value for to with the recipient phone number in E.164 format.
Replace the value for from with your Twilio phone number in E.164 format.
Replace the value for twiml with your desired TwiML instructions.
To use a hosted TwiML URL, replace twiml with url and set the value to the URL that hosts your TwiML instructions. For example:
url="http://demo.twilio.com/docs/voice.xml"
The following voice.xml file is hosted at http://demo.twilio.com/docs/voice.xml uses the <Say> and the <Play> TwiML tags to read a message and play an MP3 file for the user.
1
<?xmlversion="1.0"encoding="UTF-8"?>
2
<Response>
3
<Sayvoice="Polly.Joanna-Generative">Thanks for trying our documentation. Enjoy!</Say>
To use a TwiML application to handle calls, replace twiml with application_sid and set the value to your TwiML application's SID. You can create and configure applications on the TwiML apps page in Console (Develop > TwiML apps). If you're using legacy Console, go to Voice > Manage > TwiML apps.
application_sid="<YOUR_TWIML_APP_SID>"
When your outbound call is connected, Twilio will make a request to the Voice URL set on your application.
(warning)
Warning
The application_sid take precedence over the twiml and url parameters and ignores the following parameters: method, fallback_url, fallback_method, status_callback, status_callback_method. Twilio expects that your application handles all of this information. Learn more about the Calls resource.
Save your changes and run this command from your terminal in the directory that contains make_call.py:
pythonmake_call.py
After a few moments, you receive a call from your Twilio number.
Create and open a new file called make_call.js anywhere on your machine and paste in the following code:
Make an outbound call with TwiML
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
consttwilio=require("twilio");// Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID at twilio.com/console
5
// Provision API Keys at twilio.com/console/runtime/api-keys
6
// and set the environment variables. See http://twil.io/secure
7
// For local testing, you can use your Account SID and Auth token
To learn all of the API response values that you can return with console.log(), see the response for Create a call in the API documentation. Precede the response value with call. (for example: console.log(call.sid) returns the sid value).
Set the environment variables for your Account SID, API key SID, and API key secret.
On Mac or Linux:
Run the following commands to add your credentials as environment variables in a twilio.env file and source them. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
If you're committing code with git, run the following command to add the twilio.env file to .gitignore to avoid uploading your credentials in plain text:
echo"twilio.env">>.gitignore
On Windows command line (cmd.exe):
Run the following commands. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
Replace the value for to with the recipient phone number in E.164 format.
Replace the value for from with your Twilio phone number in E.164 format.
Replace the value for twiml with your desired TwiML instructions.
To use a hosted TwiML URL, replace twiml with url and set the value to the URL that hosts your TwiML instructions. For example:
url="http://demo.twilio.com/docs/voice.xml"
The following voice.xml file is hosted at http://demo.twilio.com/docs/voice.xml uses the <Say> and the <Play> TwiML tags to read a message and play an MP3 file for the user.
1
<?xmlversion="1.0"encoding="UTF-8"?>
2
<Response>
3
<Sayvoice="Polly.Joanna-Generative">Thanks for trying our documentation. Enjoy!</Say>
To use a TwiML application to handle calls, replace twiml with applicationSid and set the value to your TwiML application's SID. You can create and configure applications on the TwiML apps page in Console (Develop > TwiML apps). If you're using legacy Console, go to Voice > Manage > TwiML apps.
applicationSid="<YOUR_TWIML_APP_SID>"
When your outbound call is connected, Twilio will make a request to the Voice URL set on your application.
(warning)
Warning
The applicationSid take precedence over the twiml and url parameters and ignores the following parameters: method, fallbackUrl, fallbackMethod, statusCallback, statusCallbackMethod. Twilio expects that your application handles all of this information. Learn more about the Calls resource.
Save your changes and run this command from your terminal in the directory that contains make_call.js:
nodemake_call.js
After a few moments, you receive a call from your Twilio number.
Create and open a new file called make_call.php anywhere on your machine and paste in the following code:
Make an outbound call with TwiML
1
<?php
2
3
// Update the path below to your autoload.php,
4
// see https://getcomposer.org/doc/01-basic-usage.md
5
require_once"/path/to/vendor/autoload.php";
6
7
useTwilio\Rest\Client;
8
9
// Find your Account SID at twilio.com/console
10
// Provision API Keys at twilio.com/console/runtime/api-keys
11
// and set the environment variables. See http://twil.io/secure
12
// For local testing, you can use your Account SID and Auth token
To learn all of the API response values that you can return with print, see the response for Create a call in the API documentation. Precede the response value with $call-> (for example: print($call->sid) returns the sid value).
Set the environment variables for your Account SID, API key SID, and API key secret.
On Mac or Linux:
Run the following commands to add your credentials as environment variables in a twilio.env file and source them. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
If you're committing code with git, run the following command to add the twilio.env file to .gitignore to avoid uploading your credentials in plain text:
echo"twilio.env">>.gitignore
On Windows command line (cmd.exe):
Run the following commands. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
Replace +14155551212 with the recipient phone number in E.164 format.
Replace +15017122661 with your Twilio phone number in E.164 format.
Replace the value for twiml with your desired TwiML instructions.
To use a hosted TwiML URL, replace twiml with url and set the value to the URL that hosts your TwiML instructions. For example:
url="http://demo.twilio.com/docs/voice.xml"
The following voice.xml file is hosted at http://demo.twilio.com/docs/voice.xml uses the <Say> and the <Play> TwiML tags to read a message and play an MP3 file for the user.
1
<?xmlversion="1.0"encoding="UTF-8"?>
2
<Response>
3
<Sayvoice="Polly.Joanna-Generative">Thanks for trying our documentation. Enjoy!</Say>
To use a TwiML application to handle calls, replace twiml with applicationSid and set the value to your TwiML application's SID. You can create and configure applications on the TwiML apps page in Console (Develop > TwiML apps). If you're using legacy Console, go to Voice > Manage > TwiML apps.
applicationSid="<YOUR_TWIML_APP_SID>"
When your outbound call is connected, Twilio will make a request to the Voice URL set on your application.
(warning)
Warning
The applicationSid take precedence over the twiml and url parameters and ignores the following parameters: method, fallbackUrl, fallbackMethod, statusCallback, statusCallbackMethod. Twilio expects that your application handles all of this information. Learn more about the Calls resource.
Update line 5 of make_call.php to require __DIR__ . '/vendor/autoload.php';
Save your changes and run this command from your terminal in the directory that contains make_call.php:
phpmake_call.php
After a few moments, you'll receive a call from your Twilio number.
Run the following commands to create a new .NET project and install the Twilio NuGet package:
1
mkdirmake-call
2
cdmake-call
3
dotnetnew app
4
dotnetadd package Twilio
Open the Program.cs file in your favorite text editor and replace its contents with the following code:
Make an outbound call with TwiML
1
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
2
3
usingSystem;
4
usingTwilio;
5
usingTwilio.Rest.Api.V2010.Account;
6
usingSystem.Threading.Tasks;
7
8
classProgram{
9
public static asyncTaskMain(string[]args) {
10
// Find your Account SID at twilio.com/console
11
// Provision API Keys at twilio.com/console/runtime/api-keys
12
// and set the environment variables. See http://twil.io/secure
13
// For local testing, you can use your Account SID and Auth token
To learn all of the API response values that you can return with Console.WriteLine(), see the response for Create a call in the API documentation. Precede the response value with call. (for example: Console.WriteLine(call.Sid) returns the sid value).
Set the environment variables for your Account SID, API key SID, and API key secret.
On Mac or Linux:
Run the following commands to add your credentials as environment variables in a twilio.env file and source them. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
If you're committing code with git, run the following command to add the twilio.env file to .gitignore to avoid uploading your credentials in plain text:
echo"twilio.env">>.gitignore
On Windows command line (cmd.exe):
Run the following commands. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
The following voice.xml file is hosted at http://demo.twilio.com/docs/voice.xml uses the <Say> and the <Play> TwiML tags to read a message and play an MP3 file for the user.
1
<?xmlversion="1.0"encoding="UTF-8"?>
2
<Response>
3
<Sayvoice="Polly.Joanna-Generative">Thanks for trying our documentation. Enjoy!</Say>
To use a TwiML application to handle calls, replace twiml with applicationSid and set the value to your TwiML application's SID. You can create and configure applications on the TwiML apps page in Console (Develop > TwiML apps). If you're using legacy Console, go to Voice > Manage > TwiML apps.
applicationSid:"<YOUR_TWIML_APP_SID>"
When your outbound call is connected, Twilio will make a request to the Voice URL set on your application.
(warning)
Warning
The applicationSid take precedence over the twiml and url parameters and ignores the following parameters: method, fallbackUrl, fallbackMethod, statusCallback, statusCallbackMethod. Twilio expects that your application handles all of this information. Learn more about the Calls resource.
Save your changes and run this command from your terminal in the directory that contains Program.cs:
dotnetrun
After a few moments, you'll receive a call from your Twilio number.
Run the following commands to create a new Java project using Gradle:
1
mkdirmake-call
2
cdmake-call
3
gradleinit--typebasic--dslgroovy--use-defaults
4
mkdir-psrc/main/java
Replace the contents of the build.gradle file with the following:
1
plugins {
2
id'java'
3
id'application'
4
}
5
6
application {
7
mainClass='Example'
8
}
9
10
repositories {
11
mavenCentral()
12
}
13
14
dependencies {
15
implementation'com.twilio.sdk:twilio:10.5.2'
16
implementation'org.slf4j:slf4j-simple:2.0.16'
17
implementation'com.sparkjava:spark-core:2.9.4'
18
}
Create and open a new file called make_call.java in the src/main/java directory and paste in the following code:
Make an outbound call with TwiML
1
// Install the Java helper library from twilio.com/docs/java/install
2
3
importcom.twilio.type.Twiml;
4
importcom.twilio.Twilio;
5
importcom.twilio.rest.api.v2010.account.Call;
6
7
public classExample{
8
// Find your Account SID at twilio.com/console
9
// Provision API Keys at twilio.com/console/runtime/api-keys
10
// and set the environment variables. See http://twil.io/secure
11
// For local testing, you can use your Account SID and Auth token
12
public static finalString API_KEY=System.getenv("TWILIO_API_KEY");
13
public static finalString API_SECRET=System.getenv("TWILIO_API_SECRET");
14
public static finalString ACCOUNT_SID=System.getenv("TWILIO_ACCOUNT_SID");
To learn all of the API response values that you can return with System.out.println(), see the response for Create a call in the API documentation. Precede the response value with call.get (for example: System.out.println(call.getSid()) returns the sid value).
Set the environment variables for your Account SID, API key SID, and API key secret.
On Mac or Linux:
Run the following commands to add your credentials as environment variables in a twilio.env file and source them. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
If you're committing code with git, run the following command to add the twilio.env file to .gitignore to avoid uploading your credentials in plain text:
echo"twilio.env">>.gitignore
On Windows command line (cmd.exe):
Run the following commands. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
The following voice.xml file is hosted at http://demo.twilio.com/docs/voice.xml uses the <Say> and the <Play> TwiML tags to read a message and play an MP3 file for the user.
1
<?xmlversion="1.0"encoding="UTF-8"?>
2
<Response>
3
<Sayvoice="Polly.Joanna-Generative">Thanks for trying our documentation. Enjoy!</Say>
To use a TwiML application to handle calls, replace twiml with applicationSid and set the value to your TwiML application's SID. You can create and configure applications on the TwiML apps page in Console (Develop > TwiML apps). If you're using legacy Console, go to Voice > Manage > TwiML apps.
applicationSid="<YOUR_TWIML_APP_SID>";
When your outbound call is connected, Twilio will make a request to the Voice URL set on your application.
(warning)
Warning
The applicationSid take precedence over the twiml and url parameters and ignores the following parameters: method, fallbackUrl, fallbackMethod, statusCallback, statusCallbackMethod. Twilio expects that your application handles all of this information. Learn more about the Calls resource.
Run this command from your terminal in the directory that contains build.gradle:
gradlerun
After a few moments, you'll receive a call from your Twilio number.
Create a new project folder and the Go module:
1
mkdirmake-call
2
cdmake-call
3
gomod init make-call
Create and open a new file called make_call.go anywhere on your machine and paste in the following code:
Make an outbound call with TwiML
1
// Download the helper library from https://www.twilio.com/docs/go/install
2
packagemain
3
4
import(
5
"fmt"
6
"github.com/twilio/twilio-go"
7
api"github.com/twilio/twilio-go/rest/api/v2010"
8
"os"
9
)
10
11
funcmain() {
12
// Find your Account SID at twilio.com/console
13
// Provision API Keys at twilio.com/console/runtime/api-keys
14
// and set the environment variables. See http://twil.io/secure
15
// For local testing, you can use your Account SID and Auth token
To learn all of the API response values that you can return with fmt.Println(), see the response for Create a call in the API documentation. Precede the response value with call. (for example: fmt.Println(call.Sid) returns the sid value).
Set the environment variables for your Account SID, API key SID, and API key secret.
On Mac or Linux:
Run the following commands to add your credentials as environment variables in a twilio.env file and source them. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
If you're committing code with git, run the following command to add the twilio.env file to .gitignore to avoid uploading your credentials in plain text:
echo"twilio.env">>.gitignore
On Windows command line (cmd.exe):
Run the following commands. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
The following voice.xml file is hosted at http://demo.twilio.com/docs/voice.xml uses the <Say> and the <Play> TwiML tags to read a message and play an MP3 file for the user.
1
<?xmlversion="1.0"encoding="UTF-8"?>
2
<Response>
3
<Sayvoice="Polly.Joanna-Generative">Thanks for trying our documentation. Enjoy!</Say>
To use a TwiML application to handle calls, replace Twiml with ApplicationSid and set the value to your TwiML application's SID. You can create and configure applications on the TwiML apps page in Console (Develop > TwiML apps). If you're using legacy Console, go to Voice > Manage > TwiML apps.
params.SetApplicationSid("<YOUR_TWIML_APP_SID>")
When your outbound call is connected, Twilio will make a request to the Voice URL set on your application.
(warning)
Warning
The ApplicationSid take precedence over the Twiml and Url parameters and ignores the following parameters: Method, FallbackUrl, FallbackMethod, StatusCallback, StatusCallbackMethod. Twilio expects that your application handles all of this information. Learn more about the Calls resource.
Save your changes and run this command from your terminal in the directory that contains make_call.go:
1
goget
2
gorun make_call.go
After a few moments, you'll receive a call from your Twilio number.
Create and open a new file called make_call.rb anywhere on your machine and paste in the following code:
Make an outbound call with TwiML
1
# Download the helper library from https://www.twilio.com/docs/ruby/install
2
require'twilio-ruby'
3
4
# Find your Account SID at twilio.com/console
5
# Provision API Keys at twilio.com/console/runtime/api-keys
6
# and set the environment variables. See http://twil.io/secure
7
# For local testing, you can use your Account SID and Auth token
To learn all of the API response values that you can return with puts, see the response for Create a call in the API documentation. Precede the response value with call. (for example: puts call.sid returns the sid value).
Set the environment variables for your Account SID, API key SID, and API key secret.
On Mac or Linux:
Run the following commands to add your credentials as environment variables in a twilio.env file and source them. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
If you're committing code with git, run the following command to add the twilio.env file to .gitignore to avoid uploading your credentials in plain text:
echo"twilio.env">>.gitignore
On Windows command line (cmd.exe):
Run the following commands. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Account SID, SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your API key SID, and your_api_secret with your API key secret.
Replace the value for to with the recipient phone number in E.164 format.
Replace the value for from with your Twilio phone number in E.164 format.
Replace the value for twiml with your desired TwiML instructions.
To use a hosted TwiML URL, replace twiml with url and set the value to the URL that hosts your TwiML instructions. For example:
url:"http://demo.twilio.com/docs/voice.xml",
The following voice.xml file is hosted at http://demo.twilio.com/docs/voice.xml uses the <Say> and the <Play> TwiML tags to read a message and play an MP3 file for the user.
1
<?xmlversion="1.0"encoding="UTF-8"?>
2
<Response>
3
<Sayvoice="Polly.Joanna-Generative">Thanks for trying our documentation. Enjoy!</Say>
To use a TwiML application to handle calls, replace twiml with application_sid and set the value to your TwiML application's SID. You can create and configure applications on the TwiML apps page in Console (Develop > TwiML apps). If you're using legacy Console, go to Voice > Manage > TwiML apps.
application_sid:"<YOUR_TWIML_APP_SID>",
When your outbound call is connected, Twilio will make a request to the Voice URL set on your application.
(warning)
Warning
The application_sid take precedence over the twiml and url parameters and ignores the following parameters: method, fallback_url, fallback_method, status_callback, status_callback_method. Twilio expects that your application handles all of this information. Learn more about the Calls resource.
Save your changes and run this command from your terminal in the directory that contains make_call.rb:
rubymake_call.rb
After a few moments, you'll receive a call from your Twilio number.
Manage your outbound call
Optionally, you can configure additional parameters when making outbound calls to customize call behavior. Below are some common use cases.
Send digits
To dial an extension, set the SendDigits parameter to the sequence of digits to send after the call connects.
You can include any digit (0-9), A, B, C, D, #, or *.
To add pauses, use w for a half-second pause or W for a one-second pause between digits.
To receive the outcome of calls, set the StatusCallback parameter to your status callback URL.
After Twilio completes your call, it'll make an asynchronous request to the URL. If you don't provide a StatusCallback URL, Twilio will end the call without sending any status updates to your application.
To specify the HTTP request method Twilio should use when making requests to the StatusCallback URL, set the StatusCallbackMethod parameter to either GET or POST. The default is POST.
To specify which call progress events should trigger a request to your StatusCallback URL, set the StatusCallbackEvent parameter to either initiated, ringing, answered, or completed. To specify multiple values, separate them with a space. The default is completed.
Recording a call is subject to the same obligations and requirements as the Recordings resource and the <Record> TwiML verb. For workflows subject to PCI or the Health Insurance Portability and the Accountability Act (HIPAA), see the applicable documentation.
To record your outbound call, set the Record parameter and set its value to true. You can also configure the following optional parameters to manage your call recordings:
To receive the recording and other information about the call, set the RecordingStatusCallback parameter to a URL that Twilio will request when the recording is available.
To specify the HTTP request method Twilio should use when making requests to the RecordingStatusCallback URL, set the RecordingStatusCallbackMethod parameter to either GET or POST. The default is POST.
To specify which recording status changes should trigger a request to your RecordingStatusCallback URL, set the RecordingStatusCallbackEvent parameter to either completed, absent, or in-progress. To specify multiple values, separate them with a space.
Use cases for making outbound calls with Twilio Programmable Voice
This guide teaches the basics required for the following use cases:
Send notifications with Twilio Programmable Voice
You can use this guide to programmatically call customers to notify them of important updates, such as appointment reminders, delivery alerts, or emergency notices. Combine outbound calls with the <Say> TwiML verb to play a text-to-speech message, or with the Url parameter to run a custom TwiML workflow when the call connects.
To learn more advanced features that you can use with notifications, see Voice notifications.
Build outbound call centers with Twilio Programmable Voice
You can use this guide as the entry point for dialer and campaign workflows. Programmatically place calls to leads or customers, then use the StatusCallback and Record parameters to track outcomes and capture call audio for quality assurance.
To learn more advanced features that you can use with outbound call centers, see Voice outbound call centers.
Result
After following this guide, you can programmatically place outbound phone calls using Twilio Programmable Voice and the Twilio SDKs. You will have built code that plays TwiML instructions on a call, sends DTMF digits, and receives call status and recording callbacks.
Next steps
Explore the following guides to build on what you've learned in this guide: