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.
The unique string that we created to identify the PhoneNumber resource.
^PN[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Account that created the PhoneNumber resource.
^AC[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the Service the resource is associated with.
^MG[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The date and time in GMT when the resource was created specified in ISO 8601 format.
The date and time in GMT when the resource was last updated specified in ISO 8601 format.
The phone number in E.164 format, which consists of a + followed by the country code and subscriber number.
An array of values that describe whether the number can receive calls or messages. Can be: Voice
, SMS
, and MMS
.
The absolute URL of the PhoneNumber resource.
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.
application/x-www-form-urlencoded
The SID of the Phone Number being added to the Service.
^PN[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function createPhoneNumber() {11const phoneNumber = await client.messaging.v112.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.phoneNumbers.create({14phoneNumberSid: "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",15});1617console.log(phoneNumber.sid);18}1920createPhoneNumber();
1{2"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"date_created": "2015-07-30T20:12:31Z",6"date_updated": "2015-07-30T20:12:33Z",7"phone_number": "+987654321",8"country_code": "US",9"capabilities": [],10"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"11}
GET https://messaging.twilio.com/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}
The SID of the Service to fetch the resource from.
^MG[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the PhoneNumber resource to fetch.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function fetchPhoneNumber() {11const phoneNumber = await client.messaging.v112.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.phoneNumbers("PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.fetch();1516console.log(phoneNumber.sid);17}1819fetchPhoneNumber();
1{2"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",3"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",4"service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",5"date_created": "2015-07-30T20:12:31Z",6"date_updated": "2015-07-30T20:12:33Z",7"phone_number": "12345",8"country_code": "US",9"capabilities": [],10"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"11}
GET https://messaging.twilio.com/v1/Services/{ServiceSid}/PhoneNumbers
How many resources to return in each list page. The default is 50, and the maximum is 1000.
1
Maximum: 1000
The page token. This is provided by the API.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function listPhoneNumber() {11const phoneNumbers = await client.messaging.v112.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.phoneNumbers.list({ limit: 20 });1415phoneNumbers.forEach((p) => console.log(p.sid));16}1718listPhoneNumber();
1{2"meta": {3"page": 0,4"page_size": 20,5"first_page_url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers?PageSize=20&Page=0",6"previous_page_url": null,7"next_page_url": null,8"key": "phone_numbers",9"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers?PageSize=20&Page=0"10},11"phone_numbers": [12{13"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",14"service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",15"sid": "PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",16"date_created": "2015-07-30T20:12:31Z",17"date_updated": "2015-07-30T20:12:33Z",18"phone_number": "+987654321",19"country_code": "US",20"capabilities": [],21"url": "https://messaging.twilio.com/v1/Services/MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/PhoneNumbers/PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"22}23]24}
DELETE https://messaging.twilio.com/v1/Services/{ServiceSid}/PhoneNumbers/{Sid}
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.
The SID of the Service to delete the resource from.
^MG[0-9a-fA-F]{32}$
Min length: 34
Max length: 34
The SID of the PhoneNumber resource to delete.
1// Download the helper library from https://www.twilio.com/docs/node/install2const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";34// Find your Account SID and Auth Token at twilio.com/console5// and set the environment variables. See http://twil.io/secure6const accountSid = process.env.TWILIO_ACCOUNT_SID;7const authToken = process.env.TWILIO_AUTH_TOKEN;8const client = twilio(accountSid, authToken);910async function deletePhoneNumber() {11await client.messaging.v112.services("MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")13.phoneNumbers("PNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")14.remove();15}1617deletePhoneNumber();