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

phonenumber-properties page anchor
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_updatedstring<date-time>

The date and time in GMT when the resource was last updated specified in RFC 2822(link takes you to an external page) 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

create-a-phonenumber-resource page anchor
POST https://trunking.twilio.com/v1/Trunks/{TrunkSid}/PhoneNumbers

Path parameters

path-parameters page anchor
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
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

create-a-phonenumber page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

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

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

read-multiple-phonenumber-resources page anchor
GET https://trunking.twilio.com/v1/Trunks/{TrunkSid}/PhoneNumbers

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

list-multiple-phonenumbers page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_14
// Download the helper library from https://www.twilio.com/docs/node/install
_14
import twilio from "twilio";
_14
_14
// Find your Account SID and Auth Token at twilio.com/console
_14
// and set the environment variables. See http://twil.io/secure
_14
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_14
const authToken = process.env.TWILIO_AUTH_TOKEN;
_14
const client = twilio(accountSid, authToken);
_14
_14
const phoneNumbers = await client.trunking.v1
_14
.trunks("TKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_14
.phoneNumbers.list({ limit: 20 });
_14
_14
phoneNumbers.forEach((p) => console.log(p.accountSid));

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-a-phonenumber-resource page anchor
DELETE https://trunking.twilio.com/v1/Trunks/{TrunkSid}/PhoneNumbers/{Sid}

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
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

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


Rate this page: