REST API: Test Credentials

Twilio provides you with a set of test credentials so you can exercise parts of the REST API without charging your account. You can find your credentials in the Developer Tools section of your Dashboard.

You use these credentials in the same way as your live credentials. However, when you authenticate with your test credentials, we will not charge your account, update the state of your account, or connect to real phone numbers. You can now pretend to buy a phone number, or send an SMS, without actually doing so.

To protect your production data, your test credentials can't interact with the data in your real account. For example, you can't use phone numbers from your real account as the 'From' number in requests made with your test credentials.

Supported Resources

Your test credentials can currently be used to interact with the following three resources:

  • Buying phone numbers: POST /2010-04-01/Accounts/{TestAccountSid}/IncomingPhoneNumbers
  • Sending SMS messages: POST /2010-04-01/Accounts/{TestAccountSid}/SMS/Messages
  • Making calls: POST /2010-04-01/Accounts/{TestAccountSid}/Calls

Requests to any other resource with test credentials will receive a 403 Forbidden response. In the future, we may enable these resources for testing as well.

Magic Input

When you make an API request with your test credentials, Twilio will validate all input as though the request were made with your real credentials. However, there are some cases when a request's validity depends on the state of Twilio. For instance, if you are trying to buy a phone number and that phone number is no longer available, Twilio will return an error.

In order to write test cases that expect and handle errors which depend on the state of Twilio, we provide magic inputs. For the case mentioned above, there is a magic phone number +15005550000 which, if you pass it as the 'PhoneNumber' parameter in a POST to IncomingPhoneNumbers, will always return an error saying the number is unavailable.

The full set of magic inputs is detailed below.

Test Buying A Number

If you'd like to test API requests to the phone numbers resource without actually provisioning a number for your account, you can use your test credentials.

You use these credentials in exactly the same way as your live credentials. However, when you authenticate with your test credentials, we will not charge your account or purchase a phone number for you. This way, you can pretend to buy a phone number without actually doing so.

Just POST to the normal phone number purchase API endpoint using your test credentials to authenticate and your TestAccountSid in the URL:

POST https://api.twilio.com/2010-04-01/Accounts/{TestAccountSid}/IncomingPhoneNumbers

Searching for phone numbers using your test credentials is not supported yet, but will be coming soon.

Parameters

All of the existing phone number purchase parameters will work. In addition, we provide some specific values for certain parameters to help you generate success and failure cases.

PhoneNumber
Value Description Error Code
+15005550000 This phone number is unavailable. 21422
+15005550001 This phone number is invalid. 21421
+15005550006 This phone number is valid and available. No error
AreaCode
Value Description Error Code
533 This area code doesn't have any available phone numbers. 21452
500 This area code has an available number. No error
Example 1

Successfully provision a number. Purchase will always complete successfully if you attempt to purchase the magic number +15005550006. Any other parameters you send with the request, such as a VoiceUrl or a StatusCallback, will be included in the API response.

test-incoming-phone-numbers-example-1
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
  • json
  • xml
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers \
    -d "VoiceUrl=http://demo.twilio.com/docs/voice.xml" \
    -d "PhoneNumber=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers.json \
    -d "VoiceUrl=http://demo.twilio.com/docs/voice.xml" \
    -d "PhoneNumber=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var options = new PhoneNumberOptions();
    options.VoiceUrl = "http://demo.twilio.com/docs/voice.xml";
    options.PhoneNumber = "+15005550006";
    var number = twilio.AddIncomingPhoneNumber(options);
    
    Console.WriteLine(number.Sid);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.IncomingPhoneNumberFactory;
import com.twilio.sdk.resource.instance.IncomingPhoneNumber;
import com.twilio.sdk.resource.list.IncomingPhoneNumberList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the IncomingPhoneNumberList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("VoiceUrl", "http://demo.twilio.com/docs/voice.xml"));
    params.add(new BasicNameValuePair("PhoneNumber", "+15005550006"));
    
    
    IncomingPhoneNumberFactory numberFactory = client.getAccount().getIncomingPhoneNumberFactory();
    IncomingPhoneNumber number = numberFactory.create(params);
    System.out.println(number.getSid());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.incomingPhoneNumbers.create({
    voiceUrl: "http://demo.twilio.com/docs/voice.xml",
    phoneNumber: "+15005550006"
}, function(err, number) {
    process.stdout.write(number.sid);
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

$number = $client->account->incoming_phone_numbers->create(array(
        "VoiceUrl" => "http://demo.twilio.com/docs/voice.xml",
    "PhoneNumber" => "+15005550006"
    ));
echo $number->sid;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

number = client.phone_numbers.purchase(voice_url="http://demo.twilio.com/docs/voice.xml",
    phone_number="+15005550006")
print(number.sid)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

number = @client.account.incoming_phone_numbers.create(:voice_url => "http://demo.twilio.com/docs/voice.xml",
    :phone_number => "+15005550006")
puts number.sms_url
Show Output
  • JSON
  • XML
{
    "sid":"PNbc8e66614955250fc32ae5bacbd73902",
    "account_sid":"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "friendly_name":"(500) 555-0006",
    "phone_number":"+15005550006",
    "voice_url":"http://demo.twilio.com/docs/voice.xml",
    "voice_method":"POST",
    "voice_fallback_url":"",
    "voice_fallback_method":"POST",
    "voice_caller_id_lookup":false,
    "date_created":"Wed, 10 Oct 2012 21:36:14 +0000",
    "date_updated":"Wed, 10 Oct 2012 21:36:14 +0000",
    "sms_url":"",
    "sms_method":"POST",
    "sms_fallback_url":"",
    "sms_fallback_method":"POST",
    "capabilities":{
        "voice":false,
        "sms":false
    },
    "status_callback":"",
    "status_callback_method":"POST",
    "api_version":"2010-04-01",
    "voice_application_sid":"",
    "sms_application_sid":"",
    "uri":"\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/IncomingPhoneNumbers\/PNbc8e66614955250fc32ae5bacbd73902.json"
}
<TwilioResponse>
    <IncomingPhoneNumber>
        <Sid>PN378279e21f1c90ea1c5377f554978cec</Sid>
        <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
        <FriendlyName>(500) 555-0006</FriendlyName>
        <PhoneNumber>+15005550006</PhoneNumber>
        <VoiceUrl>http://demo.twilio.com/docs/voice.xml</VoiceUrl>
        <VoiceMethod>POST</VoiceMethod>
        <VoiceFallbackUrl></VoiceFallbackUrl>
        <VoiceFallbackMethod>POST</VoiceFallbackMethod>
        <VoiceCallerIdLookup>false</VoiceCallerIdLookup>
        <DateCreated/><DateUpdated/>
        <SmsUrl></SmsUrl>
        <SmsMethod>POST</SmsMethod>
        <SmsFallbackUrl></SmsFallbackUrl>
        <SmsFallbackMethod>POST</SmsFallbackMethod>
        <Capabilities>
            <Voice>false</Voice>
            <SMS>false</SMS>
        </Capabilities>
        <StatusCallback></StatusCallback>
        <StatusCallbackMethod>POST</StatusCallbackMethod>
        <ApiVersion>2010-04-01</ApiVersion>
        <VoiceApplicationSid></VoiceApplicationSid>
        <SmsApplicationSid></SmsApplicationSid>
        <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers/PN378279e21f1c90ea1c5377f554978cec</Uri>
    </IncomingPhoneNumber>
</TwilioResponse>
Example 2

Attempt to purchase an unavailable number. Trigger this by passing the magic number +15005550000.

test-incoming-phone-numbers-example-2
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
  • json
  • xml
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers \
    -d "PhoneNumber=%2B15005550000" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers.json \
    -d "PhoneNumber=%2B15005550000" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var options = new PhoneNumberOptions();
    options.PhoneNumber = "+15005550000";
    var number = twilio.AddIncomingPhoneNumber(options);
    
    Console.WriteLine(number.Sid);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.IncomingPhoneNumberFactory;
import com.twilio.sdk.resource.instance.IncomingPhoneNumber;
import com.twilio.sdk.resource.list.IncomingPhoneNumberList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the IncomingPhoneNumberList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("PhoneNumber", "+15005550000"));
    
    
    IncomingPhoneNumberFactory numberFactory = client.getAccount().getIncomingPhoneNumberFactory();
    IncomingPhoneNumber number = numberFactory.create(params);
    System.out.println(number.getSid());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.incomingPhoneNumbers.create({
    phoneNumber: "+15005550000"
}, function(err, number) {
    process.stdout.write(number.sid);
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

$number = $client->account->incoming_phone_numbers->create(array(
        "PhoneNumber" => "+15005550000"
    ));
echo $number->sid;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

number = client.phone_numbers.purchase(phone_number="+15005550000")
print(number.sid)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

number = @client.account.incoming_phone_numbers.create(:phone_number => "+15005550000")
puts number.sms_url
Show Output
  • JSON
  • XML
{
    "status":400,
    "message":"+15005550000 is not available",
    "code":21422,
    "more_info":"http:\/\/www.twilio.com\/docs\/errors\/21422"
}
<TwilioResponse>
  <RestException>
    <Status>400</Status>
    <Message>+15005550000 is not available</Message>
    <Code>21422</Code>
    <MoreInfo>http://www.twilio.com/docs/errors/21422</MoreInfo>
  </RestException>
</TwilioResponse>
Example 3: Attempt to buy invalid number

Just specify an invalid number as your input. Twilio will try to convert letters to numbers, but specifying a very short or very long string of either will fail.

test-post-example-3
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
  • json
  • xml
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers \
    -d "PhoneNumber=33" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers.json \
    -d "PhoneNumber=33" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var options = new PhoneNumberOptions();
    options.PhoneNumber = "33";
    var number = twilio.AddIncomingPhoneNumber(options);
    
    Console.WriteLine(number.Sid);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.IncomingPhoneNumberFactory;
import com.twilio.sdk.resource.instance.IncomingPhoneNumber;
import com.twilio.sdk.resource.list.IncomingPhoneNumberList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the IncomingPhoneNumberList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("PhoneNumber", "33"));
    
    
    IncomingPhoneNumberFactory numberFactory = client.getAccount().getIncomingPhoneNumberFactory();
    IncomingPhoneNumber number = numberFactory.create(params);
    System.out.println(number.getSid());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.incomingPhoneNumbers.create({
    phoneNumber: "33"
}, function(err, number) {
    process.stdout.write(number.sid);
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

$number = $client->account->incoming_phone_numbers->create(array(
        "PhoneNumber" => "33"
    ));
echo $number->sid;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

number = client.phone_numbers.purchase(phone_number="33")
print(number.sid)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

number = @client.account.incoming_phone_numbers.create(:phone_number => "33")
puts number.phone_number
Show Output
  • JSON
  • XML
{
    "status":400,
    "message":"33 is not a valid number",
    "code":21421,
    "more_info":"http:\/\/www.twilio.com\/docs\/errors\/21421"
}
<TwilioResponse>
  <RestException>
    <Status>400</Status>
    <Message>33 is not a valid number</Message>
    <Code>21421</Code>
    <MoreInfo>http://www.twilio.com/docs/errors/21421</MoreInfo>
  </RestException>
</TwilioResponse>

Test Sending an SMS

If you'd like to test API requests to send SMS messages without charging your account or sending an SMS, you can use your test credentials.

Just POST to the normal SMS API endpoint using your test credentials to authenticate and your TestAccountSid in the URL:

POST https://api.twilio.com/2010-04-01/Accounts/{TestAccountSid}/SMS/Messages

Parameters

All of the existing outbound SMS parameters will work. In addition, we provide some specific values for certain parameters to help you generate success and failure cases.

From

Your test credentials don't have access to any valid 'From' phone numbers on your real account. Therefore the only phone numbers you should use as 'From' numbers are the magic numbers listed here.

Value Description Error Code
+15005550001 This phone number is invalid. 21212
+15005550007 This phone number is not owned by your account or is not SMS-capable. 21606
+15005550008 This number has an SMS message queue that is full. 21611
+15005550006 This number passes all validation. No error
All Others This phone number is not owned by your account or is not SMS-capable. 21606
To
Value Description Error Code
+15005550001 This phone number is invalid. 21211
+15005550002 Twilio cannot route to this number. 21612
+15005550003 Your account doesn't have the international permissions necessary to SMS this number. 21408
+15005550004 This number is blacklisted for your account. 21610
+15005550009 This number is incapable of receiving SMS messages. 21614
All Others Any other phone number is validated normally. Input-dependent
Example 1

Successfully send an SMS. Trigger this by sending an SMS using the magic number +15005550006 as the From number, and a regular phone number for the To number.

test-sms-messages-example-1
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
  • json
  • xml
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages \
    -d "Body=All%20in%20the%20game%2C%20yo" \
    -d "To=%2B14108675309" \
    -d "From=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages.json \
    -d "Body=All%20in%20the%20game%2C%20yo" \
    -d "To=%2B14108675309" \
    -d "From=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    
    var sms = twilio.SendSmsMessage("+15005550006", "+14108675309", "All in the game, yo", "");
    
    Console.WriteLine(sms.Sid);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.SmsFactory;
import com.twilio.sdk.resource.instance.Sms;
import com.twilio.sdk.resource.list.SmsList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the SmsList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Body", "All in the game, yo"));
    params.add(new BasicNameValuePair("To", "+14108675309"));
    params.add(new BasicNameValuePair("From", "+15005550006"));
    
    
    SmsFactory smsFactory = client.getAccount().getSmsFactory();
    Sms sms = smsFactory.create(params);
    System.out.println(sms.getSid());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.sms.messages.create({
    body: "All in the game, yo",
    to: "+14108675309",
    from: "+15005550006"
}, function(err, sms) {
    process.stdout.write(sms.sid);
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

$sms = $client->account->sms_messages->create("+15005550006", "+14108675309", "All in the game, yo", array());
echo $sms->sid;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

sms = client.sms.messages.create(body="All in the game, yo",
    to="+14108675309",
    from_="+15005550006")
print(sms.sid)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

sms = @client.account.sms.messages.create(:body => "All in the game, yo",
    :to => "+14108675309",
    :from => "+15005550006")
puts sms.body
Show Output
  • JSON
  • XML
{
    "sid":"SM711c87aba9a3ed02554c91a7d503b64e",
    "date_created":"Wed, 10 Oct 2012 17:57:42 +0000",
    "date_updated":"Wed, 10 Oct 2012 17:57:42 +0000",
    "date_sent":null,
    "account_sid":"ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "to":"+14108675309",
    "from":"+15005550006",
    "body":"hi",
    "status":"queued",
    "direction":"outbound-api",
    "api_version":"2010-04-01",
    "price":null,
    "uri":"\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/SMS\/Messages\/SM711c87aba9a3ed02554c91a7d503b64e.json"
}
<TwilioResponse>
    <SMSMessage>
        <Sid>SM7408b094c1433819dd79a8c2c2c0b35e</Sid>
        <DateCreated>Wed, 10 Oct 2012 17:59:08 +0000</DateCreated>
        <DateUpdated>Wed, 10 Oct 2012 17:59:08 +0000</DateUpdated>
        <DateSent/>
        <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
        <To>+14108675309</To>
        <From>+15005550006</From>
        <Body>All in the game, yo</Body>
        <Status>queued</Status>
        <Direction>outbound-api</Direction>
        <ApiVersion>2010-04-01</ApiVersion>
        <Price/>
        <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages/SM7408b094c1433819dd79a8c2c2c0b35e</Uri>
    </SMSMessage>
</TwilioResponse>
Example 2

Attempt to send a message to a non-mobile number. Trigger this by passing the magic number +15005550009 as the To number.

test-sms-messages-example-2
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
  • json
  • xml
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages \
    -d "Body=Hey%20Mr%20Nugget%2C%20you%20the%20bomb%21" \
    -d "To=%2B15005550009" \
    -d "From=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages.json \
    -d "Body=Hey%20Mr%20Nugget%2C%20you%20the%20bomb%21" \
    -d "To=%2B15005550009" \
    -d "From=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    
    var sms = twilio.SendSmsMessage("+15005550006", "+15005550009", "Hey Mr Nugget, you the bomb!", "");
    
    Console.WriteLine(sms.Sid);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.SmsFactory;
import com.twilio.sdk.resource.instance.Sms;
import com.twilio.sdk.resource.list.SmsList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the SmsList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Body", "Hey Mr Nugget, you the bomb!"));
    params.add(new BasicNameValuePair("To", "+15005550009"));
    params.add(new BasicNameValuePair("From", "+15005550006"));
    
    
    SmsFactory smsFactory = client.getAccount().getSmsFactory();
    Sms sms = smsFactory.create(params);
    System.out.println(sms.getSid());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.sms.messages.create({
    body: "Hey Mr Nugget, you the bomb!",
    to: "+15005550009",
    from: "+15005550006"
}, function(err, sms) {
    process.stdout.write(sms.sid);
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

$sms = $client->account->sms_messages->create("+15005550006", "+15005550009", "Hey Mr Nugget, you the bomb!", array());
echo $sms->sid;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

sms = client.sms.messages.create(body="Hey Mr Nugget, you the bomb!",
    to="+15005550009",
    from_="+15005550006")
print(sms.sid)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

sms = @client.account.sms.messages.create(:body => "Hey Mr Nugget, you the bomb!",
    :to => "+15005550009",
    :from => "+15005550006")
puts sms.from
Show Output
  • JSON
  • XML
{
    "status":400,
    "message":"To number: +15005550009, is not a mobile number",
    "code":21614,
    "more_info":"http:\/\/www.twilio.com\/docs\/errors\/21614"
}
<TwilioResponse>
  <RestException>
    <Status>400</Status>
    <Message>To number: +15005550009, is not a mobile number</Message>
    <Code>21614</Code>
    <MoreInfo>http://www.twilio.com/docs/errors/21614</MoreInfo>
  </RestException>
</TwilioResponse>
Example 3

Attempt to send a message with an empty SMS body. No need for magic numbers, the validation error will be raised normally.

test-sms-messages-example-3
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
  • json
  • xml
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages \
    -d "To=%2B14108675309" \
    -d "From=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages.json \
    -d "To=%2B14108675309" \
    -d "From=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    
    var sms = twilio.SendSmsMessage("+15005550006", "+14108675309", "", "");
    
    Console.WriteLine(sms.Sid);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.SmsFactory;
import com.twilio.sdk.resource.instance.Sms;
import com.twilio.sdk.resource.list.SmsList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the SmsList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("To", "+14108675309"));
    params.add(new BasicNameValuePair("From", "+15005550006"));
    
    
    SmsFactory smsFactory = client.getAccount().getSmsFactory();
    Sms sms = smsFactory.create(params);
    System.out.println(sms.getSid());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.sms.messages.create({
    to: "+14108675309",
    from: "+15005550006"
}, function(err, sms) {
    process.stdout.write(sms.sid);
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

$sms = $client->account->sms_messages->create("+15005550006", "+14108675309", null, array());
echo $sms->sid;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

sms = client.sms.messages.create(to="+14108675309",
    from_="+15005550006")
print(sms.sid)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

sms = @client.account.sms.messages.create(:to => "+14108675309",
    :from => "+15005550006")
puts sms.to
Show Output
  • JSON
  • XML
{
    "status":400,
    "message":"Message body is required.",
    "code":21602,
    "more_info":"http:\/\/www.twilio.com\/docs\/errors\/21602"
}
<TwilioResponse>
    <RestException>
        <Status>400</Status>
        <Message>Message body is required.</Message>
        <Code>21602</Code>
        <MoreInfo>http://www.twilio.com/docs/errors/21602</MoreInfo>
    </RestException>
</TwilioResponse>

Test Making a Call

If you'd like to test API requests to the outbound call endpoint without charging your account or making a call, you can use your test credentials. Note that since no call is made, Twilio will not make a request to the URL passed in the 'Url' parameter and no TwiML will be executed.

Just POST to the normal outbound call API endpoint using your test credentials to authenticate and your TestAccountSid in the URL:

POST https://api.twilio.com/2010-04-01/Accounts/{TestAccountSid}/Calls

Parameters

All of the existing outbound call parameters will work. In addition, we provide some specific values for certain parameters to help you generate success and failure cases.

From

Your test credentials don't have access to any valid 'From' phone numbers on your real account. Therefore the only phone number you should use as a 'From' number is the magic number listed here.

Value Description Error Code
+15005550001 This phone number is invalid. 21212
+15005550006 This number is a valid From number for your account. No error
All Others The phone number is not verified for your account. 21210
To
Value Description Error Code
+15005550001 This phone number is invalid. 21217
+15005550002 Twilio cannot route to this number. 21214
+15005550003 Your account doesn't have the international permissions necessary to call this number. 21215
+15005550004 This number is blacklisted for your account. 21216
All Others Any other phone number is validated normally. Input-dependent
Example 1

Successfully enqueue an outgoing call. Use the magic number +15005550006 as the From number and any regular number as the To number.

test-calls-example-1
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
  • json
  • xml
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls \
    -d "Url=http://demo.twilio.com/docs/voice.xml" \
    -d "To=%2B14108675309" \
    -d "From=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
    -d "Url=http://demo.twilio.com/docs/voice.xml" \
    -d "To=%2B14108675309" \
    -d "From=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var options = new CallOptions();
    options.Url = "http://demo.twilio.com/docs/voice.xml";
    options.To = "+14108675309";
    options.From = "+15005550006";
    var call = twilio.InitiateOutboundCall(options);
    
    Console.WriteLine(call.Sid);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.CallFactory;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the CallList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
    params.add(new BasicNameValuePair("To", "+14108675309"));
    params.add(new BasicNameValuePair("From", "+15005550006"));
    
    
    CallFactory callFactory = client.getAccount().getCallFactory();
    Call call = callFactory.create(params);
    System.out.println(call.getSid());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.calls.create({
    url: "http://demo.twilio.com/docs/voice.xml",
    to: "+14108675309",
    from: "+15005550006"
}, function(err, call) {
    process.stdout.write(call.sid);
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

$call = $client->account->calls->create("+15005550006", "+14108675309", "http://demo.twilio.com/docs/voice.xml", array());
echo $call->sid;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

call = client.calls.create(url="http://demo.twilio.com/docs/voice.xml",
    to="+14108675309",
    from_="+15005550006")
print(call.sid)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

call = @client.account.calls.create(:url => "http://demo.twilio.com/docs/voice.xml",
    :to => "+14108675309",
    :from => "+15005550006")
puts call.start_time
Show Output
  • JSON
  • XML
{
  "sid": "CA074e4ce7f21c4d6bc889bb96480d42ff",
  "date_created": "Wed, 10 Oct 2012 22:40:24 +0000",
  "date_updated": "Wed, 10 Oct 2012 22:40:24 +0000",
  "parent_call_sid": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+14108675309",
  "to_formatted": "(410) 555-1234",
  "from": "+15005550006",
  "from_formatted": "(500) 555-0006",
  "phone_number_sid": null,
  "status": "queued",
  "start_time": null,
  "end_time": null,
  "duration": null,
  "price": null,
  "direction": null,
  "answered_by": null,
  "api_version": null,
  "annotation": null,
  "forwarded_from": null,
  "group_sid": null,
  "caller_name": null,
  "uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA074e4ce7f21c4d6bc889bb96480d42ff.json",
  "subresource_uris": {
    "notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA074e4ce7f21c4d6bc889bb96480d42ff\/Notifications.json",
    "recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CA074e4ce7f21c4d6bc889bb96480d42ff\/Recordings.json"
  }
}
<TwilioResponse>
  <Call>
    <Sid>CA7a7a8cbd55adaf0e84dcba31e454e623</Sid>
    <DateCreated>Wed, 10 Oct 2012 22:40:24 +0000</DateCreated>
    <DateUpdated>Wed, 10 Oct 2012 22:40:24 +0000</DateUpdated>
    <ParentCallSid/>
    <AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
    <To>+14108675309</To>
    <ToFormatted>(410) 555-1234</ToFormatted>
    <From>+15005550006</From>
    <FromFormatted>(500) 555-0006</FromFormatted>
    <PhoneNumberSid/>
    <Status>queued</Status>
    <StartTime/>
    <EndTime/>
    <Duration/>
    <Price/>
    <Direction/>
    <AnsweredBy/>
    <ApiVersion/>
    <Annotation/>
    <ForwardedFrom/>
    <GroupSid/>
    <CallerName/>
    <Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA7a7a8cbd55adaf0e84dcba31e454e623</Uri>
    <SubresourceUris>
      <Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA7a7a8cbd55adaf0e84dcba31e454e623/Notifications</Notifications>
      <Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CA7a7a8cbd55adaf0e84dcba31e454e623/Recordings</Recordings>
    </SubresourceUris>
  </Call>
</TwilioResponse>
Example 2

Attempt to call an international number in a country without permissions turned on. Trigger this by passing the magic number +15005550003 as the To number.

test-calls-example-2
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
  • json
  • xml
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls \
    -d "Url=http://demo.twilio.com/docs/voice.xml" \
    -d "To=%2B15005550003" \
    -d "From=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
    -d "Url=http://demo.twilio.com/docs/voice.xml" \
    -d "To=%2B15005550003" \
    -d "From=%2B15005550006" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var options = new CallOptions();
    options.Url = "http://demo.twilio.com/docs/voice.xml";
    options.To = "+15005550003";
    options.From = "+15005550006";
    var call = twilio.InitiateOutboundCall(options);
    
    Console.WriteLine(call.Sid);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.CallFactory;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the CallList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
    params.add(new BasicNameValuePair("To", "+15005550003"));
    params.add(new BasicNameValuePair("From", "+15005550006"));
    
    
    CallFactory callFactory = client.getAccount().getCallFactory();
    Call call = callFactory.create(params);
    System.out.println(call.getSid());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.calls.create({
    url: "http://demo.twilio.com/docs/voice.xml",
    to: "+15005550003",
    from: "+15005550006"
}, function(err, call) {
    process.stdout.write(call.sid);
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

$call = $client->account->calls->create("+15005550006", "+15005550003", "http://demo.twilio.com/docs/voice.xml", array());
echo $call->sid;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

call = client.calls.create(url="http://demo.twilio.com/docs/voice.xml",
    to="+15005550003",
    from_="+15005550006")
print(call.sid)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

call = @client.account.calls.create(:url => "http://demo.twilio.com/docs/voice.xml",
    :to => "+15005550003",
    :from => "+15005550006")
puts call.direction
Show Output
  • JSON
  • XML
{
    "status":400,
    "message":"Account not authorized to call +14005550003. Perhaps you need to enable some international permissions: https:\/\/www.twilio.com\/user\/account\/international",
    "code":21215,
    "more_info":"http:\/\/www.twilio.com\/docs\/errors\/21215"
}
<TwilioResponse>
    <RestException>
        <Status>400</Status>
		<Message>Account not authorized to call +14005550003. Perhaps you need to enable some international permissions: https://www.twilio.com/user/account/settings/international</Message>
        <Code>21215</Code>
        <MoreInfo>http://www.twilio.com/docs/errors/21215</MoreInfo>
    </RestException>
</TwilioResponse>