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

Messaging Service PhoneNumber Resource


(warning)

Public Beta

The Service Resource is currently available as a Public Beta product. This means that some features for configuring your Messaging Service via the REST API are not yet implemented, and others may be changed before the product is declared Generally Available. Messaging Service Configuration through the Twilio Console is Generally Available.

Public Beta products are not covered by a Twilio SLA.

The resources for sending Messages with a Messaging Service are Generally Available.

The PhoneNumber subresource of a Service instance represents a phone number you have associated to the Service.

When sending a message with your Messaging Service, Twilio will select a phone number from the service for delivery.

Inbound messages received on any phone number associated to a Messaging Service are passed to the inbound request URL of the Service with the TWiML parameters that describe the message.


PhoneNumber Properties

Property nameTypePIIDescription
sidSID<PN>
Not PII

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

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

account_sidSID<AC>

The SID of the Account that created the PhoneNumber resource.

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

service_sidSID<MG>

The SID of the Service the resource is associated with.

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

date_createdstring<date-time>

The date and time in GMT when the resource was created specified in ISO 8601 format.


date_updatedstring<date-time>

The date and time in GMT when the resource was last updated specified in ISO 8601 format.


phone_numberstring<phone-number>

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


country_codestring

The 2-character ISO Country Code of the number.


capabilitiesarray[string]

An array of values that describe whether the number can receive calls or messages. Can be: Voice, SMS, and MMS.


urlstring<uri>

The absolute URL of the PhoneNumber resource.


Create a PhoneNumber Resource (Add a Phone Number to a Messaging Service)

POST https://messaging.twilio.com/v1/Services/{ServiceSid}/PhoneNumbers

Add a Phone Number to your Messaging Service by creating a PhoneNumber resource.

Each Service can have no more than 400 phone numbers by default. If you think you might need a higher limit, contact Twilio Support about a Messaging Service number limit increase, and include an explanation of your use case.

Path parameters

Property nameTypeRequiredPIIDescription
ServiceSidSID<MG>required

The SID of the Service to create the resource under.

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

Request body parameters

Property nameTypeRequiredPIIDescription
PhoneNumberSidSID<PN>required

The SID of the Phone Number being added to the Service.

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

Add a Phone Number to a Messaging Service

Create a PhoneNumber Resource to add it to a Messaging Service

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.messaging.v1
_20
.services("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_20
.phoneNumbers.create({
_20
phoneNumberSid: "PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_20
});
_20
_20
console.log(phoneNumber.sid);
_20
}
_20
_20
createPhoneNumber();

Output

_11
{
_11
"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_11
"date_created": "2015-07-30T20:12:31Z",
_11
"date_updated": "2015-07-30T20:12:33Z",
_11
"phone_number": "+987654321",
_11
"country_code": "US",
_11
"capabilities": [],
_11
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_11
}


Fetch a PhoneNumber resource

GET https://messaging.twilio.com/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}

Path parameters

Property nameTypeRequiredPIIDescription
ServiceSidSID<MG>required

The SID of the Service to fetch the resource from.

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

Sidstringrequired

The SID of the PhoneNumber resource to fetch.

Fetch a PhoneNumber

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 fetchPhoneNumber() {
_19
const phoneNumber = await client.messaging.v1
_19
.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_19
.phoneNumbers("Sid")
_19
.fetch();
_19
_19
console.log(phoneNumber.sid);
_19
}
_19
_19
fetchPhoneNumber();

Output

_11
{
_11
"sid": "Sid",
_11
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_11
"date_created": "2015-07-30T20:12:31Z",
_11
"date_updated": "2015-07-30T20:12:33Z",
_11
"phone_number": "12345",
_11
"country_code": "US",
_11
"capabilities": [],
_11
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_11
}


Read multiple PhoneNumber resources

GET https://messaging.twilio.com/v1/Services/{ServiceSid}/PhoneNumbers

Path parameters

Property nameTypeRequiredPIIDescription
ServiceSidSID<MG>required

The SID of the Service to read the resources from.

Pattern: ^MG[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.messaging.v1
_18
.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_18
.phoneNumbers.list({ limit: 20 });
_18
_18
phoneNumbers.forEach((p) => console.log(p.sid));
_18
}
_18
_18
listPhoneNumber();

Output

_24
{
_24
"meta": {
_24
"page": 0,
_24
"page_size": 20,
_24
"first_page_url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers?PageSize=20&Page=0",
_24
"previous_page_url": null,
_24
"next_page_url": null,
_24
"key": "phone_numbers",
_24
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers?PageSize=20&Page=0"
_24
},
_24
"phone_numbers": [
_24
{
_24
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_24
"service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_24
"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_24
"date_created": "2015-07-30T20:12:31Z",
_24
"date_updated": "2015-07-30T20:12:33Z",
_24
"phone_number": "+987654321",
_24
"country_code": "US",
_24
"capabilities": [],
_24
"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
_24
}
_24
]
_24
}


Delete a PhoneNumber resource

DELETE https://messaging.twilio.com/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}

(warning)

Warning

Removing a phone number from the Service does not release the number from your account. You must release a phone number from your Account to disassociate and delete the phone number from the Service.

Returns a "204 NO CONTENT" if the phone number was successfully removed from the service.

Path parameters

Property nameTypeRequiredPIIDescription
ServiceSidSID<MG>required

The SID of the Service to delete the resource from.

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

Sidstringrequired

The SID of the PhoneNumber resource to delete.

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.messaging.v1
_17
.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_17
.phoneNumbers("Sid")
_17
.remove();
_17
}
_17
_17
deletePhoneNumber();


Rate this page: