Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

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 Auth Tokens page of your Console.

You use these credentials in the same way as your live credentials, with one restriction being that you cannot log in to the Twilio CLI with your test 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}/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.

(warning)

Warning

A limitation of SMS messages and calls made using test credentials is that they will not trigger status callbacks. Learn more about status callbacks for outbound SMS and status callbacks for Voice.


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.

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 provisioning a number for your account, you can use your test credentials.

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 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:


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

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

ValueDescriptionError Code
+15005550000This phone number is unavailable.21422
+15005550001This phone number is invalid.21421
+15005550006This phone number is valid and available.No error

AreaCode

ValueDescriptionError Code
533This area code doesn't have any available phone numbers.21452
500This area code has an available number.No error

Example 1

Successfully provision a number. Purchase will always be completed 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.

Purchase a number

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_19
// Download the helper library from https://www.twilio.com/docs/node/install
_19
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19
_19
// Find your Account SID and Auth Token at twilio.com/console
_19
// and set the environment variables. See http://twil.io/secure
_19
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19
const authToken = process.env.TWILIO_AUTH_TOKEN;
_19
const client = twilio(accountSid, authToken);
_19
_19
async function createIncomingPhoneNumber() {
_19
const incomingPhoneNumber = await client.incomingPhoneNumbers.create({
_19
phoneNumber: "+15005550006",
_19
voiceUrl: "http://demo.twilio.com/docs/voice.xml",
_19
});
_19
_19
console.log(incomingPhoneNumber.accountSid);
_19
}
_19
_19
createIncomingPhoneNumber();

Output

_44
{
_44
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_44
"address_requirements": "none",
_44
"address_sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"api_version": "2010-04-01",
_44
"beta": false,
_44
"capabilities": {
_44
"voice": true,
_44
"sms": false,
_44
"mms": true,
_44
"fax": false
_44
},
_44
"date_created": "Thu, 30 Jul 2015 23:19:04 +0000",
_44
"date_updated": "Thu, 30 Jul 2015 23:19:04 +0000",
_44
"emergency_status": "Active",
_44
"emergency_address_sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"emergency_address_status": "registered",
_44
"friendly_name": "friendly_name",
_44
"identity_sid": "RIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"origin": "origin",
_44
"phone_number": "+15005550006",
_44
"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"sms_application_sid": "APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"sms_fallback_method": "GET",
_44
"sms_fallback_url": "https://example.com",
_44
"sms_method": "GET",
_44
"sms_url": "https://example.com",
_44
"status_callback": "https://example.com",
_44
"status_callback_method": "GET",
_44
"trunk_sid": null,
_44
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
_44
"voice_application_sid": "APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"voice_caller_id_lookup": false,
_44
"voice_fallback_method": "GET",
_44
"voice_fallback_url": "https://example.com",
_44
"voice_method": "GET",
_44
"voice_url": "http://demo.twilio.com/docs/voice.xml",
_44
"bundle_sid": "BUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"voice_receive_mode": "voice",
_44
"status": "in-use",
_44
"subresource_uris": {
_44
"assigned_add_ons": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AssignedAddOns.json"
_44
}
_44
}

Example 2

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

Attempt to purchase an unavailable number

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function createIncomingPhoneNumber() {
_18
const incomingPhoneNumber = await client.incomingPhoneNumbers.create({
_18
phoneNumber: "+15005550000",
_18
});
_18
_18
console.log(incomingPhoneNumber.accountSid);
_18
}
_18
_18
createIncomingPhoneNumber();

Output

_44
{
_44
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_44
"address_requirements": "none",
_44
"address_sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"api_version": "2010-04-01",
_44
"beta": false,
_44
"capabilities": {
_44
"voice": true,
_44
"sms": false,
_44
"mms": true,
_44
"fax": false
_44
},
_44
"date_created": "Thu, 30 Jul 2015 23:19:04 +0000",
_44
"date_updated": "Thu, 30 Jul 2015 23:19:04 +0000",
_44
"emergency_status": "Active",
_44
"emergency_address_sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"emergency_address_status": "registered",
_44
"friendly_name": "friendly_name",
_44
"identity_sid": "RIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"origin": "origin",
_44
"phone_number": "+15005550000",
_44
"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"sms_application_sid": "APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"sms_fallback_method": "GET",
_44
"sms_fallback_url": "https://example.com",
_44
"sms_method": "GET",
_44
"sms_url": "https://example.com",
_44
"status_callback": "https://example.com",
_44
"status_callback_method": "GET",
_44
"trunk_sid": null,
_44
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
_44
"voice_application_sid": "APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"voice_caller_id_lookup": false,
_44
"voice_fallback_method": "GET",
_44
"voice_fallback_url": "https://example.com",
_44
"voice_method": "GET",
_44
"voice_url": "https://example.com",
_44
"bundle_sid": "BUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"voice_receive_mode": "voice",
_44
"status": "in-use",
_44
"subresource_uris": {
_44
"assigned_add_ons": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AssignedAddOns.json"
_44
}
_44
}

Example 3: Attempt to buy an 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.

Attempt to purchase an invalid number

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function createIncomingPhoneNumber() {
_18
const incomingPhoneNumber = await client.incomingPhoneNumbers.create({
_18
phoneNumber: "33",
_18
});
_18
_18
console.log(incomingPhoneNumber.accountSid);
_18
}
_18
_18
createIncomingPhoneNumber();

Output

_44
{
_44
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_44
"address_requirements": "none",
_44
"address_sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"api_version": "2010-04-01",
_44
"beta": false,
_44
"capabilities": {
_44
"voice": true,
_44
"sms": false,
_44
"mms": true,
_44
"fax": false
_44
},
_44
"date_created": "Thu, 30 Jul 2015 23:19:04 +0000",
_44
"date_updated": "Thu, 30 Jul 2015 23:19:04 +0000",
_44
"emergency_status": "Active",
_44
"emergency_address_sid": "ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"emergency_address_status": "registered",
_44
"friendly_name": "friendly_name",
_44
"identity_sid": "RIaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"origin": "origin",
_44
"phone_number": "33",
_44
"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"sms_application_sid": "APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"sms_fallback_method": "GET",
_44
"sms_fallback_url": "https://example.com",
_44
"sms_method": "GET",
_44
"sms_url": "https://example.com",
_44
"status_callback": "https://example.com",
_44
"status_callback_method": "GET",
_44
"trunk_sid": null,
_44
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
_44
"voice_application_sid": "APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"voice_caller_id_lookup": false,
_44
"voice_fallback_method": "GET",
_44
"voice_fallback_url": "https://example.com",
_44
"voice_method": "GET",
_44
"voice_url": "https://example.com",
_44
"bundle_sid": "BUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_44
"voice_receive_mode": "voice",
_44
"status": "in-use",
_44
"subresource_uris": {
_44
"assigned_add_ons": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/AssignedAddOns.json"
_44
}
_44
}


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:


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

Parameters

All of the existing outbound SMS parameters will work, except for MessagingServiceSid. 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.

ValueDescriptionError Code
+15005550001This phone number is invalid.21212
+15005550007This phone number is not owned by your account or is not SMS-capable.21606
+15005550008This number has an SMS message queue that is full.21611
+15005550006This number passes all validation.No error
All OthersThis phone number is not owned by your account or is not SMS-capable.21606

To

ValueDescriptionError Code
+15005550001This phone number is invalid.21211
+15005550002Twilio cannot route to this number.21612
+15005550003Your account doesn't have the international permissions necessary to SMS this number.21408
+15005550004This number is blocked for your account.21610
+15005550009This number is incapable of receiving SMS messages.21614
All OthersAny 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.

Create a message

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_20
// Download the helper library from https://www.twilio.com/docs/node/install
_20
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20
_20
// Find your Account SID and Auth Token at twilio.com/console
_20
// and set the environment variables. See http://twil.io/secure
_20
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20
const authToken = process.env.TWILIO_AUTH_TOKEN;
_20
const client = twilio(accountSid, authToken);
_20
_20
async function createMessage() {
_20
const message = await client.messages.create({
_20
body: "All in the game, yo",
_20
from: "+15005550006",
_20
to: "+5571981265131",
_20
});
_20
_20
console.log(message.body);
_20
}
_20
_20
createMessage();

Output

_25
{
_25
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_25
"api_version": "2010-04-01",
_25
"body": "All in the game, yo",
_25
"date_created": "Thu, 30 Jul 2015 20:12:31 +0000",
_25
"date_sent": "Thu, 30 Jul 2015 20:12:33 +0000",
_25
"date_updated": "Thu, 30 Jul 2015 20:12:33 +0000",
_25
"direction": "outbound-api",
_25
"error_code": null,
_25
"error_message": null,
_25
"from": "+15005550006",
_25
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_25
"num_media": "0",
_25
"num_segments": "1",
_25
"price": null,
_25
"price_unit": null,
_25
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_25
"status": "queued",
_25
"subresource_uris": {
_25
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
_25
},
_25
"tags": null,
_25
"to": "+5571981265131",
_25
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_25
}

Example 2

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

Attempt to send a message to a non-mobile number

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_20
// Download the helper library from https://www.twilio.com/docs/node/install
_20
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20
_20
// Find your Account SID and Auth Token at twilio.com/console
_20
// and set the environment variables. See http://twil.io/secure
_20
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20
const authToken = process.env.TWILIO_AUTH_TOKEN;
_20
const client = twilio(accountSid, authToken);
_20
_20
async function createMessage() {
_20
const message = await client.messages.create({
_20
body: "Hey Mr Nugget, you the bomb!",
_20
from: "+15005550006",
_20
to: "+15005550009",
_20
});
_20
_20
console.log(message.body);
_20
}
_20
_20
createMessage();

Output

_28
{
_28
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_28
"api_version": "2010-04-01",
_28
"body": "Hey Mr Nugget, you the bomb!",
_28
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"direction": "outbound-api",
_28
"error_code": null,
_28
"error_message": null,
_28
"from": "+15005550006",
_28
"num_media": "0",
_28
"num_segments": "1",
_28
"price": null,
_28
"price_unit": null,
_28
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"status": "queued",
_28
"subresource_uris": {
_28
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
_28
},
_28
"tags": {
_28
"campaign_name": "Spring Sale 2022",
_28
"message_type": "cart_abandoned"
_28
},
_28
"to": "+15005550009",
_28
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_28
}

Example 3

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

Attempt to send a message with an empty SMS body

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_20
// Download the helper library from https://www.twilio.com/docs/node/install
_20
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20
_20
// Find your Account SID and Auth Token at twilio.com/console
_20
// and set the environment variables. See http://twil.io/secure
_20
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20
const authToken = process.env.TWILIO_AUTH_TOKEN;
_20
const client = twilio(accountSid, authToken);
_20
_20
async function createMessage() {
_20
const message = await client.messages.create({
_20
body: "Do. Or do not. There is no try.",
_20
from: "+15005550006",
_20
to: "+14108675310",
_20
});
_20
_20
console.log(message.body);
_20
}
_20
_20
createMessage();

Output

_28
{
_28
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_28
"api_version": "2010-04-01",
_28
"body": "Do. Or do not. There is no try.",
_28
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"direction": "outbound-api",
_28
"error_code": null,
_28
"error_message": null,
_28
"from": "+15005550006",
_28
"num_media": "0",
_28
"num_segments": "1",
_28
"price": null,
_28
"price_unit": null,
_28
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"status": "queued",
_28
"subresource_uris": {
_28
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
_28
},
_28
"tags": {
_28
"campaign_name": "Spring Sale 2022",
_28
"message_type": "cart_abandoned"
_28
},
_28
"to": "+14108675310",
_28
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_28
}


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 request 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:


_10
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.

ValueDescriptionError Code
+15005550001This phone number is invalid.21212
+15005550006This number is a valid From number for your account.No error
All OthersThe phone number is not verified for your account.21210

To

ValueDescriptionError Code
+15005550001This phone number is invalid.21217
+15005550002Twilio cannot route to this number.21214
+15005550003Your account doesn't have the international permissions necessary to call this number.21215
+15005550004This number is blocked for your account.21216
All OthersAny 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.

Making a call

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_20
// Download the helper library from https://www.twilio.com/docs/node/install
_20
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20
_20
// Find your Account SID and Auth Token at twilio.com/console
_20
// and set the environment variables. See http://twil.io/secure
_20
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20
const authToken = process.env.TWILIO_AUTH_TOKEN;
_20
const client = twilio(accountSid, authToken);
_20
_20
async function createCall() {
_20
const call = await client.calls.create({
_20
from: "+15005550006",
_20
to: "+14108675310",
_20
url: "http://demo.twilio.com/docs/voice.xml",
_20
});
_20
_20
console.log(call.sid);
_20
}
_20
_20
createCall();

Output

_39
{
_39
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"annotation": null,
_39
"answered_by": null,
_39
"api_version": "2010-04-01",
_39
"caller_name": null,
_39
"date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
_39
"date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
_39
"direction": "inbound",
_39
"duration": "15",
_39
"end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
_39
"forwarded_from": "+141586753093",
_39
"from": "+15005550006",
_39
"from_formatted": "(415) 867-5308",
_39
"group_sid": null,
_39
"parent_call_sid": null,
_39
"phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"price": "-0.03000",
_39
"price_unit": "USD",
_39
"sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
_39
"status": "completed",
_39
"subresource_uris": {
_39
"notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
_39
"recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
_39
"payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
_39
"events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
_39
"siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
_39
"streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
_39
"transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
_39
"user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
_39
"user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
_39
},
_39
"to": "+14108675310",
_39
"to_formatted": "(415) 867-5309",
_39
"trunk_sid": null,
_39
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
_39
"queue_time": "1000"
_39
}

Example 2

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

Making a call to an international number in a country without permissions turned on

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_20
// Download the helper library from https://www.twilio.com/docs/node/install
_20
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_20
_20
// Find your Account SID and Auth Token at twilio.com/console
_20
// and set the environment variables. See http://twil.io/secure
_20
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_20
const authToken = process.env.TWILIO_AUTH_TOKEN;
_20
const client = twilio(accountSid, authToken);
_20
_20
async function createCall() {
_20
const call = await client.calls.create({
_20
from: "+15005550006",
_20
to: "+15005550003",
_20
url: "http://demo.twilio.com/docs/voice.xml",
_20
});
_20
_20
console.log(call.sid);
_20
}
_20
_20
createCall();

Output

_39
{
_39
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_39
"annotation": null,
_39
"answered_by": null,
_39
"api_version": "2010-04-01",
_39
"caller_name": null,
_39
"date_created": "Tue, 31 Aug 2010 20:36:28 +0000",
_39
"date_updated": "Tue, 31 Aug 2010 20:36:44 +0000",
_39
"direction": "inbound",
_39
"duration": "15",
_39
"end_time": "Tue, 31 Aug 2010 20:36:44 +0000",
_39
"forwarded_from": "+141586753093",
_39
"from": "+15005550006",
_39
"from_formatted": "(415) 867-5308",
_39
"group_sid": null,
_39
"parent_call_sid": null,
_39
"phone_number_sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"price": "-0.03000",
_39
"price_unit": "USD",
_39
"sid": "CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_39
"start_time": "Tue, 31 Aug 2010 20:36:29 +0000",
_39
"status": "completed",
_39
"subresource_uris": {
_39
"notifications": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Notifications.json",
_39
"recordings": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Recordings.json",
_39
"payments": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Payments.json",
_39
"events": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Events.json",
_39
"siprec": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Siprec.json",
_39
"streams": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Streams.json",
_39
"transcriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Transcriptions.json",
_39
"user_defined_message_subscriptions": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessageSubscriptions.json",
_39
"user_defined_messages": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/UserDefinedMessages.json"
_39
},
_39
"to": "+15005550003",
_39
"to_formatted": "(415) 867-5309",
_39
"trunk_sid": null,
_39
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Calls/CAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json",
_39
"queue_time": "1000"
_39
}


Rate this page: