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

PhoneNumber Resource


The Phone Numbers subresource contains the list of Phone Number instances associated with a SIP Trunk.

To purchase a new phone number for your trunk or manage your numbers more generally, you'll need to use the IncomingPhoneNumbers Resource. The SIP Trunking PhoneNumbers Resource is only for adding, removing, and viewing phone numbers associated with a SIP Trunk.


PhoneNumber Properties

Property nameTypePIIDescription
account_sidSID<AC>
Not PII

The SID of the Account that created the PhoneNumber resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

address_requirementsenum<string>

Whether the phone number requires an Address registered with Twilio and, if so, what type. Can be: none, any, local, or foreign.

Possible values:
noneanylocalforeign

api_versionstring

The API version used to start a new TwiML session.


betaboolean

Whether the phone number is new to the Twilio platform. Can be: true or false.


capabilitiesobject<string-map>

The set of Boolean properties that indicate whether a phone number can receive calls or messages. Capabilities are Voice, SMS, and MMS and each capability can be: true or false.


date_createdstring<date-time>

date_updatedstring<date-time>

The date and time in GMT when the resource was last updated specified in RFC 2822 format.


friendly_namestring
PII MTL: 30 days

The string that you assigned to describe the resource.


linksobject<uri-map>

The URLs of related resources.


phone_numberstring<phone-number>

The phone number in E.164 format, which consists of a + followed by the country code and subscriber number.


sidSID<PN>

The unique string that we created to identify the PhoneNumber resource.

Pattern: ^PN[0-9a-fA-F]{32}$Min length: 34Max length: 34

sms_application_sidSID<AP>

The SID of the application that handles SMS messages sent to the phone number. If an sms_application_sid is present, we ignore all sms_*_url values and use those of the application.

Pattern: ^AP[0-9a-fA-F]{32}$Min length: 34Max length: 34

sms_fallback_methodenum<http-method>

The HTTP method we use to call sms_fallback_url. Can be: GET or POST.

Possible values:
GETPOST

sms_fallback_urlstring<uri>

The URL that we call using the sms_fallback_method when an error occurs while retrieving or executing the TwiML from sms_url.


sms_methodenum<http-method>

The HTTP method we use to call sms_url. Can be: GET or POST.

Possible values:
GETPOST

sms_urlstring<uri>

The URL we call using the sms_method when the phone number receives an incoming SMS message.


status_callbackstring<uri>

The URL we call using the status_callback_method to send status information to your application.


status_callback_methodenum<http-method>

The HTTP method we use to call status_callback. Can be: GET or POST.

Possible values:
GETPOST

trunk_sidSID<TK>

The SID of the Trunk that handles calls to the phone number. If a trunk_sid is present, we ignore all of the voice URLs and voice applications and use those set on the Trunk. Setting a trunk_sid will automatically delete your voice_application_sid and vice versa.

Pattern: ^TK[0-9a-fA-F]{32}$Min length: 34Max length: 34

urlstring<uri>

The absolute URL of the resource.


voice_application_sidSID<AP>

The SID of the application that handles calls to the phone number. If a voice_application_sid is present, we ignore all of the voice URLs and use those set on the application. Setting a voice_application_sid will automatically delete your trunk_sid and vice versa.

Pattern: ^AP[0-9a-fA-F]{32}$Min length: 34Max length: 34

voice_caller_id_lookupboolean

Whether we look up the caller's caller-ID name from the CNAM database ($0.01 per look up). Can be: true or false.


voice_fallback_methodenum<http-method>

The HTTP method that we use to call voice_fallback_url. Can be: GET or POST.

Possible values:
GETPOST

voice_fallback_urlstring<uri>

The URL that we call using the voice_fallback_method when an error occurs retrieving or executing the TwiML requested by url.


voice_methodenum<http-method>

The HTTP method we use to call voice_url. Can be: GET or POST.

Possible values:
GETPOST

voice_urlstring<uri>

The URL we call using the voice_method when the phone number receives a call. The voice_url is not be used if a voice_application_sid or a trunk_sid is set.


Create a PhoneNumber resource

POST https://trunking.twilio.com/v1/Trunks/{TrunkSid}/PhoneNumbers

Path parameters

Property nameTypeRequiredPIIDescription
TrunkSidSID<TK>required

The SID of the Trunk to associate the phone number with.

Pattern: ^TK[0-9a-fA-F]{32}$Min length: 34Max length: 34

Request body parameters

Property nameTypeRequiredPIIDescription
PhoneNumberSidSID<PN>required

The SID of the Incoming Phone Number that you want to associate with the trunk.

Pattern: ^PN[0-9a-fA-F]{32}$Min length: 34Max length: 34

Create a PhoneNumber

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 createPhoneNumber() {
_20
const phoneNumber = await client.trunking.v1
_20
.trunks("TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_20
.phoneNumbers.create({
_20
phoneNumberSid: "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_20
});
_20
_20
console.log(phoneNumber.accountSid);
_20
}
_20
_20
createPhoneNumber();

Output

_34
{
_34
"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_34
"date_created": "2010-12-10T17:27:34Z",
_34
"date_updated": "2015-10-09T11:36:32Z",
_34
"friendly_name": "(415) 867-5309",
_34
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_34
"phone_number": "+14158675309",
_34
"api_version": "2010-04-01",
_34
"voice_caller_id_lookup": null,
_34
"voice_url": "https://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Proxy/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/Call",
_34
"voice_method": "POST",
_34
"voice_fallback_url": null,
_34
"voice_fallback_method": null,
_34
"status_callback": "",
_34
"status_callback_method": "POST",
_34
"voice_application_sid": "",
_34
"trunk_sid": "TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_34
"sms_url": "https://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Proxy/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/Message",
_34
"sms_method": "POST",
_34
"sms_fallback_url": "",
_34
"sms_fallback_method": "POST",
_34
"sms_application_sid": "APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_34
"address_requirements": "none",
_34
"beta": false,
_34
"url": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_34
"capabilities": {
_34
"voice": true,
_34
"sms": true,
_34
"mms": true
_34
},
_34
"links": {
_34
"phone_number": "https://api.twilio.com/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_34
}
_34
}


Read multiple PhoneNumber resources

GET https://trunking.twilio.com/v1/Trunks/{TrunkSid}/PhoneNumbers

Path parameters

Property nameTypeRequiredPIIDescription
TrunkSidSID<TK>required

The SID of the Trunk from which to read the PhoneNumber resources.

Pattern: ^TK[0-9a-fA-F]{32}$Min length: 34Max length: 34

Query parameters

Property nameTypeRequiredPIIDescription
PageSizeintegerOptional

How many resources to return in each list page. The default is 50, and the maximum is 1000.

Minimum: 1Maximum: 1000

PageintegerOptional

The page index. This value is simply for client state.

Minimum: 0

PageTokenstringOptional

The page token. This is provided by the API.

List multiple PhoneNumbers

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 listPhoneNumber() {
_18
const phoneNumbers = await client.trunking.v1
_18
.trunks("TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_18
.phoneNumbers.list({ limit: 20 });
_18
_18
phoneNumbers.forEach((p) => console.log(p.accountSid));
_18
}
_18
_18
listPhoneNumber();

Output

_47
{
_47
"meta": {
_47
"first_page_url": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers?PageSize=1&Page=0",
_47
"key": "phone_numbers",
_47
"next_page_url": null,
_47
"page": 0,
_47
"page_size": 1,
_47
"previous_page_url": null,
_47
"url": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers?PageSize=1&Page=0"
_47
},
_47
"phone_numbers": [
_47
{
_47
"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_47
"date_created": "2010-12-10T17:27:34Z",
_47
"date_updated": "2015-10-09T11:36:32Z",
_47
"friendly_name": "(415) 867-5309",
_47
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_47
"phone_number": "+14158675309",
_47
"api_version": "2010-04-01",
_47
"voice_caller_id_lookup": null,
_47
"voice_url": "https://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Proxy/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/Call",
_47
"voice_method": "POST",
_47
"voice_fallback_url": null,
_47
"voice_fallback_method": null,
_47
"status_callback": "",
_47
"status_callback_method": "POST",
_47
"voice_application_sid": "",
_47
"trunk_sid": "TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_47
"sms_url": "https://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Proxy/KSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Webhooks/Message",
_47
"sms_method": "POST",
_47
"sms_fallback_url": "",
_47
"sms_fallback_method": "POST",
_47
"sms_application_sid": "APaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_47
"address_requirements": "none",
_47
"beta": false,
_47
"url": "https://trunking.twilio.com/v1/Trunks/TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_47
"capabilities": {
_47
"voice": true,
_47
"sms": true,
_47
"mms": true
_47
},
_47
"links": {
_47
"phone_number": "https://api.twilio.com/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/IncomingPhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_47
}
_47
}
_47
]
_47
}


Delete a PhoneNumber resource

DELETE https://trunking.twilio.com/v1/Trunks/{TrunkSid}/PhoneNumbers/{Sid}

Path parameters

Property nameTypeRequiredPIIDescription
TrunkSidSID<TK>required

The SID of the Trunk from which to delete the PhoneNumber resource.

Pattern: ^TK[0-9a-fA-F]{32}$Min length: 34Max length: 34

SidSID<PN>required

The unique string that we created to identify the PhoneNumber resource to delete.

Pattern: ^PN[0-9a-fA-F]{32}$Min length: 34Max length: 34

Delete a PhoneNumber

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

_17
// Download the helper library from https://www.twilio.com/docs/node/install
_17
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_17
_17
// Find your Account SID and Auth Token at twilio.com/console
_17
// and set the environment variables. See http://twil.io/secure
_17
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_17
const authToken = process.env.TWILIO_AUTH_TOKEN;
_17
const client = twilio(accountSid, authToken);
_17
_17
async function deletePhoneNumber() {
_17
await client.trunking.v1
_17
.trunks("TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_17
.phoneNumbers("PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_17
.remove();
_17
}
_17
_17
deletePhoneNumber();


Rate this page: