Phone Numbers Subresource

Public Beta
Twilio's Messaging Services API is currently available as a Public Beta product. Some features are not yet implemented and others may be changed before the product is declared as Generally Available.
Public Beta products are not covered by a Twilio SLA.

The Phone Numbers subresource of a Service instance represents the phone numbers you have associated to the Service.

When sending a message with your Messaging Service, Copilot will select one of these phone numbers for delivery.

Inbound messages received on any phone number associated to a Messaging Service are passed to the inbound request URL of the Service. Twilio will make HTTP requests with the following parameters and values to the application you have hosted in this URL.

Properties

Each phone number has these properties:

Property Description
sid The 34 character unique sid of the Phone Number.
account_sid The 34 character unique sid of the Account.
service_sid The 34 character unique sid of the Service.
date_created The date that this resource was created.
date_updated The date that this resource was last updated.
phone_number The E.164 format of the phone number.
country_code The 2 character ISO Country Code of the number.
capabilities Any array of values that indicate whether the number can receive calls or messages. Possible capabilities are Voice, SMS, and MMS.
url The absolute URL for this resource.

List all Phone Numbers in a Service

GET /Services/{Service SID}/PhoneNumbers
Loading Code Samples...
Language
SDK Version:
  • 5.x
Response Format:
  • json
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • JSON
// Download the Node helper library from twilio.com/docs/libraries/node
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';

const client = require('twilio')(accountSid, authToken);
const service = client.messaging.services('MG2172dd2db502e20dd981ef0d67850e1a');

service.phoneNumbers.list()
       .then(function(response) {
         console.log(response);
       }).catch(function(error) {
         console.log(error);
       });
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Messaging.V1.Service;


class Example
{
    static void Main (string[] args)
    {
      // Find your Account SID and Auth Token at twilio.com/console
      const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
      const string authToken = "your_auth_token";
      const string pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";

      TwilioClient.Init(accountSid, authToken);

      var phoneNumbers = PhoneNumberResource.Read(pathServiceSid);

      foreach (var phoneNumber in phoneNumbers)
      {
        Console.WriteLine(phoneNumber.Sid);
      }
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;

$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
$twilio = new Client($account_sid, $auth_token);

$phoneNumbers = $twilio->messaging->v1->services("MG2172dd2db502e20dd981ef0d67850e1a")
                                      ->phoneNumbers->read();

foreach ($phoneNumbers as $phoneNumber) {
    print($phoneNumber->phoneNumber);
}
# Get twilio-ruby from twilio.com/docs/libraries/ruby
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@phone_numbers = @client.messaging.v1
  .services('MG2172dd2db502e20dd981ef0d67850e1a')
  .phone_numbers.list

@phone_numbers.each do |phone_number|
  puts phone_number.phone_number
end
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

phone_numbers = client.messaging \
                      .services(sid="MG2172dd2db502e20dd981ef0d67850e1a") \
                      .phone_numbers \
                      .list()

for phone_number in phone_numbers:
    print(phone_number.sid)
import com.twilio.Twilio;
import com.twilio.base.ResourceSet;
import com.twilio.rest.messaging.v1.service.PhoneNumber;

public class Example {
    // Find your Account Sid and Token at twilio.com/console
    public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    public static final String AUTH_TOKEN = "your_auth_token";

    public static void main(String[] args) {
        // Initialize the client
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

        String pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
        ResourceSet<PhoneNumber> phoneNumbers = PhoneNumber.reader(pathServiceSid)
                                                           .read();

        for (PhoneNumber phoneNumber : phoneNumbers) {
            System.out.println(phoneNumber);
        }
    }
}
curl 'https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers' \
    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{
    "meta": {
        "page": 0,
        "page_size": 50,
        "first_page_url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers?PageSize=50&Page=0",
        "previous_page_url": null,
        "next_page_url": null,
        "key": "phone_numbers",
        "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers?PageSize=50&Page=0"
                    },
    "phone_numbers": [
        {
            "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            "service_sid": "MG2172dd2db502e20dd981ef0d67850e1a",
            "sid": "PN557ce644e5ab84fa21cc21112e22c485",
            "date_created": "2017-03-14T20:12:31Z",
            "date_updated": "2017-03-14T20:12:33Z",
            "phone_number": "+987654321",
            "country_code": "US",
            "capabilities": ["sms", "mms"],
            "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN557ce644e5ab84fa21cc21112e22c485"
        },
        {
            "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            "service_sid": "MG2172dd2db502e20dd981ef0d67850e1a",
            "sid": "PN2a0747eba6abf96b7e3c3ff0b4530f6e",
            "date_created": "2017-03-14T20:15:31Z",
            "date_updated": "2017-03-14T20:15:33Z",
            "phone_number": "+441632960556",
            "country_code": "GB",
            "capabilities": ["sms"],
            "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN2a0747eba6abf96b7e3c3ff0b4530f6e"
        }
        {
            "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            "service_sid": "MG2172dd2db502e20dd981ef0d67850e1a",
            "sid": "PN2a0747eba6abf96b7e3c3ff0b4530f6e",
            "date_created": "2017-03-14T20:15:31Z",
            "date_updated": "2017-03-14T20:15:33Z",
            "phone_number": "+611900654321",
            "country_code": "AU",
            "capabilities": ["sms"],
            "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN2a0747eba6abf96b7e3c3ff0b4530f6e"
        }
    ]
}
List all Phone Numbers in a Service

Add a Phone Number to a Service

Each Service can have a max of 400 phone numbers.

POST /Services/{Service SID}/PhoneNumbers

Required Parameter

Parameter Description
PhoneNumberSid Phone Number SID for the Phone Number being added to the Service.
Loading Code Samples...
Language
SDK Version:
  • 5.x
Response Format:
  • json
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • JSON
// Download the Node helper library from twilio.com/docs/libraries/node
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';

const client = require('twilio')(accountSid, authToken);
const service = client.messaging.services('MG2172dd2db502e20dd981ef0d67850e1a');

service.phoneNumbers.create({phoneNumberSid: 'PN557ce644e5ab84fa21cc21112e22c485'})
    .then(function(response) {
      console.log(response);
    }).catch(function(error) {
      console.log(error);
    });
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Messaging.V1.Service;


class Example
{
    static void Main (string[] args)
    {
      // Find your Account SID and Auth Token at twilio.com/console
      const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
      const string authToken = "your_auth_token";
      const string pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
      const string phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";

      TwilioClient.Init(accountSid, authToken);

      var phoneNumber = PhoneNumberResource.Create(pathServiceSid, phoneNumberSid);

      Console.WriteLine(phoneNumber.Sid);

    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;

$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
$twilio = new Client($account_sid, $auth_token);

$phoneNumber = $twilio->messaging->v1->services("MG2172dd2db502e20dd981ef0d67850e1a")
                                      ->phoneNumbers->create("PN557ce644e5ab84fa21cc21112e22c485");
# Get twilio-ruby from twilio.com/docs/libraries/ruby
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@phone_number = @client.messaging.v1
  .services('MG2172dd2db502e20dd981ef0d67850e1a')
  .phone_numbers
  .create(phone_number_sid: 'PN557ce644e5ab84fa21cc21112e22c485')

puts @phone_number.sid
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

phone_number = client.messaging \
                     .services(sid="MG2172dd2db502e20dd981ef0d67850e1a") \
                     .phone_numbers \
                     .create(phone_number_sid="PN557ce644e5ab84fa21cc21112e22c485")

print(phone_number.sid)
import com.twilio.Twilio;
import com.twilio.rest.messaging.v1.service.PhoneNumber;

public class Example {
    // Find your Account Sid and Token at twilio.com/console
    public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    public static final String AUTH_TOKEN = "your_auth_token";

    public static void main(String[] args) {
        // Initialize the client
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

        String pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
        String phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";
        PhoneNumber phoneNumber = PhoneNumber.creator(pathServiceSid, phoneNumberSid)
                                             .create();
    }
}
curl 'https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers' -X POST \
    --data-urlencode 'PhoneNumberSid=PN557ce644e5ab84fa21cc21112e22c485' \
    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{
    "sid": "PN557ce644e5ab84fa21cc21112e22c485",
    "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    "service_sid": "MG2172dd2db502e20dd981ef0d67850e1a",
    "date_created": "2017-03-14T20:12:31Z",
    "date_updated": "2017-03-14T20:12:33Z",
    "phone_number": "+15017122661",
    "country_code": "US",
    "capabilities": ["sms", "mms"],
    "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN557ce644e5ab84fa21cc21112e22c485"
}
Add a Phone Number to a Service

View a Phone Number in a Service

GET /Services/{Service SID}/PhoneNumbers/{Phone Number SID}
Loading Code Samples...
Language
SDK Version:
  • 5.x
Response Format:
  • json
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • JSON
// Download the Node helper library from twilio.com/docs/libraries/node
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';

const client = require('twilio')(accountSid, authToken);
const service = client.messaging.services('MG2172dd2db502e20dd981ef0d67850e1a');

service.phoneNumbers('PN557ce644e5ab84fa21cc21112e22c485')
       .fetch()
       .then(function(response) {
         console.log(response);
       }).catch(function(error) {
         console.log(error);
       });
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Messaging.V1.Service;


class Example
{
    static void Main (string[] args)
    {
      // Find your Account SID and Auth Token at twilio.com/console
      const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
      const string authToken = "your_auth_token";
      const string pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
      const string phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";

      TwilioClient.Init(accountSid, authToken);

      var phoneNumber = PhoneNumberResource.Fetch(pathServiceSid, phoneNumberSid);

      Console.WriteLine(phoneNumber.PhoneNumber);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;

$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
$twilio = new Client($account_sid, $auth_token);

$phoneNumbers = $twilio->messaging->v1->services("MG2172dd2db502e20dd981ef0d67850e1a")
                                      ->phoneNumbers("PN557ce644e5ab84fa21cc21112e22c485")->fetch();
# Get twilio-ruby from twilio.com/docs/libraries/ruby
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@phone_number = @client.messaging.v1
                       .services('MG2172dd2db502e20dd981ef0d67850e1a')
                       .phone_numbers('PN557ce644e5ab84fa21cc21112e22c485')
                       .fetch

puts @phone_number.phone_number
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

phone_number = client.messaging \
                     .services(sid="MG2172dd2db502e20dd981ef0d67850e1a") \
                     .phone_numbers(sid="PN557ce644e5ab84fa21cc21112e22c485") \
                     .fetch()

print(phone_number.country_code)
import com.twilio.Twilio;
import com.twilio.rest.messaging.v1.service.PhoneNumber;

public class Example {
    // Find your Account Sid and Token at twilio.com/console
    public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    public static final String AUTH_TOKEN = "your_auth_token";

    public static void main(String[] args) {
        // Initialize the client
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

        String pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
        String phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";
        PhoneNumber phoneNumber = PhoneNumber.fetcher(pathServiceSid, phoneNumberSid)
                                             .fetch();

        System.out.println(phoneNumber);
    }
}
curl 'https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN557ce644e5ab84fa21cc21112e22c485' \
    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{
    "sid": "PN557ce644e5ab84fa21cc21112e22c485",
    "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    "service_sid": "MG2172dd2db502e20dd981ef0d67850e1a",
    "date_created": "2017-03-14T20:12:31Z",
    "date_updated": "2017-03-14T20:12:33Z",
    "phone_number": "+15017122661",
    "country_code": "US",
    "capabilities": ["sms", "mms"],
    "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN557ce644e5ab84fa21cc21112e22c485"
}
View a Phone Number in a Service

Removing a phone number for 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.

DELETE /Services/{Service SID}/PhoneNumbers/{Phone Number SID}
Loading Code Samples...
Language
SDK Version:
  • 5.x
Response Format:
  • json
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • JSON
// Download the Node helper library from twilio.com/docs/libraries/node
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';

const client = require('twilio')(accountSid, authToken);
const service = client.messaging.services('MG2172dd2db502e20dd981ef0d67850e1a');

service.phoneNumbers('PN557ce644e5ab84fa21cc21112e22c485')
       .remove()
       .then(function(response) {
         console.log(response);
       }).catch(function(error) {
         console.log(error);
       });
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Messaging.V1.Service;


class Example
{
    static void Main (string[] args)
    {
      // Find your Account SID and Auth Token at twilio.com/console
      const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
      const string authToken = "your_auth_token";
      const string pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
      const string phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";

      TwilioClient.Init(accountSid, authToken);

      var deleted = PhoneNumberResource.Delete(pathServiceSid, phoneNumberSid);

      Console.WriteLine(deleted);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;

$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
$twilio = new Client($account_sid, $auth_token);

$phoneNumbers = $twilio->messaging->v1->services("MG2172dd2db502e20dd981ef0d67850e1a")
                                      ->phoneNumbers("PN557ce644e5ab84fa21cc21112e22c485")->delete();
# Get twilio-ruby from twilio.com/docs/libraries/ruby
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@deleted = @client.messaging.v1
  .services('MG2172dd2db502e20dd981ef0d67850e1a')
  .phone_numbers('PN557ce644e5ab84fa21cc21112e22c485')
  .delete

puts @deleted
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

did_delete = client.messaging \
                   .services(sid="MG2172dd2db502e20dd981ef0d67850e1a") \
                   .phone_numbers(sid="PN557ce644e5ab84fa21cc21112e22c485") \
                   .delete()

print(did_delete)
import com.twilio.Twilio;
import com.twilio.rest.messaging.v1.service.PhoneNumber;

public class Example {
    // Find your Account Sid and Token at twilio.com/console
    public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    public static final String AUTH_TOKEN = "your_auth_token";

    public static void main(String[] args) {
        // Initialize the client
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

        String pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
        String phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";
        PhoneNumber.deleter(pathServiceSid, phoneNumberSid).delete();
    }
}
curl 'https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN557ce644e5ab84fa21cc21112e22c485' -X DELETE \
    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{}
Remove a Phone Number from a Service

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

Loading Code Samples...
SDK Version:
  • 5.x
Response Format:
  • json
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • JSON
// Download the Node helper library from twilio.com/docs/libraries/node
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';

const client = require('twilio')(accountSid, authToken);
const service = client.messaging.services('MG2172dd2db502e20dd981ef0d67850e1a');

service.phoneNumbers.list()
       .then(function(response) {
         console.log(response);
       }).catch(function(error) {
         console.log(error);
       });
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Messaging.V1.Service;


class Example
{
    static void Main (string[] args)
    {
      // Find your Account SID and Auth Token at twilio.com/console
      const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
      const string authToken = "your_auth_token";
      const string pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";

      TwilioClient.Init(accountSid, authToken);

      var phoneNumbers = PhoneNumberResource.Read(pathServiceSid);

      foreach (var phoneNumber in phoneNumbers)
      {
        Console.WriteLine(phoneNumber.Sid);
      }
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;

$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
$twilio = new Client($account_sid, $auth_token);

$phoneNumbers = $twilio->messaging->v1->services("MG2172dd2db502e20dd981ef0d67850e1a")
                                      ->phoneNumbers->read();

foreach ($phoneNumbers as $phoneNumber) {
    print($phoneNumber->phoneNumber);
}
# Get twilio-ruby from twilio.com/docs/libraries/ruby
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@phone_numbers = @client.messaging.v1
  .services('MG2172dd2db502e20dd981ef0d67850e1a')
  .phone_numbers.list

@phone_numbers.each do |phone_number|
  puts phone_number.phone_number
end
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

phone_numbers = client.messaging \
                      .services(sid="MG2172dd2db502e20dd981ef0d67850e1a") \
                      .phone_numbers \
                      .list()

for phone_number in phone_numbers:
    print(phone_number.sid)
import com.twilio.Twilio;
import com.twilio.base.ResourceSet;
import com.twilio.rest.messaging.v1.service.PhoneNumber;

public class Example {
    // Find your Account Sid and Token at twilio.com/console
    public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    public static final String AUTH_TOKEN = "your_auth_token";

    public static void main(String[] args) {
        // Initialize the client
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

        String pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
        ResourceSet<PhoneNumber> phoneNumbers = PhoneNumber.reader(pathServiceSid)
                                                           .read();

        for (PhoneNumber phoneNumber : phoneNumbers) {
            System.out.println(phoneNumber);
        }
    }
}
curl 'https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers' \
    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{
    "meta": {
        "page": 0,
        "page_size": 50,
        "first_page_url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers?PageSize=50&Page=0",
        "previous_page_url": null,
        "next_page_url": null,
        "key": "phone_numbers",
        "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers?PageSize=50&Page=0"
                    },
    "phone_numbers": [
        {
            "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            "service_sid": "MG2172dd2db502e20dd981ef0d67850e1a",
            "sid": "PN557ce644e5ab84fa21cc21112e22c485",
            "date_created": "2017-03-14T20:12:31Z",
            "date_updated": "2017-03-14T20:12:33Z",
            "phone_number": "+987654321",
            "country_code": "US",
            "capabilities": ["sms", "mms"],
            "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN557ce644e5ab84fa21cc21112e22c485"
        },
        {
            "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            "service_sid": "MG2172dd2db502e20dd981ef0d67850e1a",
            "sid": "PN2a0747eba6abf96b7e3c3ff0b4530f6e",
            "date_created": "2017-03-14T20:15:31Z",
            "date_updated": "2017-03-14T20:15:33Z",
            "phone_number": "+441632960556",
            "country_code": "GB",
            "capabilities": ["sms"],
            "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN2a0747eba6abf96b7e3c3ff0b4530f6e"
        }
        {
            "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            "service_sid": "MG2172dd2db502e20dd981ef0d67850e1a",
            "sid": "PN2a0747eba6abf96b7e3c3ff0b4530f6e",
            "date_created": "2017-03-14T20:15:31Z",
            "date_updated": "2017-03-14T20:15:33Z",
            "phone_number": "+611900654321",
            "country_code": "AU",
            "capabilities": ["sms"],
            "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN2a0747eba6abf96b7e3c3ff0b4530f6e"
        }
    ]
}
SDK Version:
  • 5.x
Response Format:
  • json
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • JSON
// Download the Node helper library from twilio.com/docs/libraries/node
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';

const client = require('twilio')(accountSid, authToken);
const service = client.messaging.services('MG2172dd2db502e20dd981ef0d67850e1a');

service.phoneNumbers.create({phoneNumberSid: 'PN557ce644e5ab84fa21cc21112e22c485'})
    .then(function(response) {
      console.log(response);
    }).catch(function(error) {
      console.log(error);
    });
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Messaging.V1.Service;


class Example
{
    static void Main (string[] args)
    {
      // Find your Account SID and Auth Token at twilio.com/console
      const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
      const string authToken = "your_auth_token";
      const string pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
      const string phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";

      TwilioClient.Init(accountSid, authToken);

      var phoneNumber = PhoneNumberResource.Create(pathServiceSid, phoneNumberSid);

      Console.WriteLine(phoneNumber.Sid);

    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;

$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
$twilio = new Client($account_sid, $auth_token);

$phoneNumber = $twilio->messaging->v1->services("MG2172dd2db502e20dd981ef0d67850e1a")
                                      ->phoneNumbers->create("PN557ce644e5ab84fa21cc21112e22c485");
# Get twilio-ruby from twilio.com/docs/libraries/ruby
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@phone_number = @client.messaging.v1
  .services('MG2172dd2db502e20dd981ef0d67850e1a')
  .phone_numbers
  .create(phone_number_sid: 'PN557ce644e5ab84fa21cc21112e22c485')

puts @phone_number.sid
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

phone_number = client.messaging \
                     .services(sid="MG2172dd2db502e20dd981ef0d67850e1a") \
                     .phone_numbers \
                     .create(phone_number_sid="PN557ce644e5ab84fa21cc21112e22c485")

print(phone_number.sid)
import com.twilio.Twilio;
import com.twilio.rest.messaging.v1.service.PhoneNumber;

public class Example {
    // Find your Account Sid and Token at twilio.com/console
    public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    public static final String AUTH_TOKEN = "your_auth_token";

    public static void main(String[] args) {
        // Initialize the client
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

        String pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
        String phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";
        PhoneNumber phoneNumber = PhoneNumber.creator(pathServiceSid, phoneNumberSid)
                                             .create();
    }
}
curl 'https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers' -X POST \
    --data-urlencode 'PhoneNumberSid=PN557ce644e5ab84fa21cc21112e22c485' \
    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{
    "sid": "PN557ce644e5ab84fa21cc21112e22c485",
    "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    "service_sid": "MG2172dd2db502e20dd981ef0d67850e1a",
    "date_created": "2017-03-14T20:12:31Z",
    "date_updated": "2017-03-14T20:12:33Z",
    "phone_number": "+15017122661",
    "country_code": "US",
    "capabilities": ["sms", "mms"],
    "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN557ce644e5ab84fa21cc21112e22c485"
}
SDK Version:
  • 5.x
Response Format:
  • json
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • JSON
// Download the Node helper library from twilio.com/docs/libraries/node
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';

const client = require('twilio')(accountSid, authToken);
const service = client.messaging.services('MG2172dd2db502e20dd981ef0d67850e1a');

service.phoneNumbers('PN557ce644e5ab84fa21cc21112e22c485')
       .fetch()
       .then(function(response) {
         console.log(response);
       }).catch(function(error) {
         console.log(error);
       });
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Messaging.V1.Service;


class Example
{
    static void Main (string[] args)
    {
      // Find your Account SID and Auth Token at twilio.com/console
      const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
      const string authToken = "your_auth_token";
      const string pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
      const string phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";

      TwilioClient.Init(accountSid, authToken);

      var phoneNumber = PhoneNumberResource.Fetch(pathServiceSid, phoneNumberSid);

      Console.WriteLine(phoneNumber.PhoneNumber);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;

$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
$twilio = new Client($account_sid, $auth_token);

$phoneNumbers = $twilio->messaging->v1->services("MG2172dd2db502e20dd981ef0d67850e1a")
                                      ->phoneNumbers("PN557ce644e5ab84fa21cc21112e22c485")->fetch();
# Get twilio-ruby from twilio.com/docs/libraries/ruby
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@phone_number = @client.messaging.v1
                       .services('MG2172dd2db502e20dd981ef0d67850e1a')
                       .phone_numbers('PN557ce644e5ab84fa21cc21112e22c485')
                       .fetch

puts @phone_number.phone_number
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

phone_number = client.messaging \
                     .services(sid="MG2172dd2db502e20dd981ef0d67850e1a") \
                     .phone_numbers(sid="PN557ce644e5ab84fa21cc21112e22c485") \
                     .fetch()

print(phone_number.country_code)
import com.twilio.Twilio;
import com.twilio.rest.messaging.v1.service.PhoneNumber;

public class Example {
    // Find your Account Sid and Token at twilio.com/console
    public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    public static final String AUTH_TOKEN = "your_auth_token";

    public static void main(String[] args) {
        // Initialize the client
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

        String pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
        String phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";
        PhoneNumber phoneNumber = PhoneNumber.fetcher(pathServiceSid, phoneNumberSid)
                                             .fetch();

        System.out.println(phoneNumber);
    }
}
curl 'https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN557ce644e5ab84fa21cc21112e22c485' \
    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{
    "sid": "PN557ce644e5ab84fa21cc21112e22c485",
    "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    "service_sid": "MG2172dd2db502e20dd981ef0d67850e1a",
    "date_created": "2017-03-14T20:12:31Z",
    "date_updated": "2017-03-14T20:12:33Z",
    "phone_number": "+15017122661",
    "country_code": "US",
    "capabilities": ["sms", "mms"],
    "url": "https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN557ce644e5ab84fa21cc21112e22c485"
}
SDK Version:
  • 5.x
Response Format:
  • json
SDK Version:
  • 7.x
SDK Version:
  • 3.x
SDK Version:
  • 5.x
SDK Version:
  • 6.x
SDK Version:
  • 5.x
Format:
  • JSON
// Download the Node helper library from twilio.com/docs/libraries/node
// These consts are your accountSid and authToken from https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';

const client = require('twilio')(accountSid, authToken);
const service = client.messaging.services('MG2172dd2db502e20dd981ef0d67850e1a');

service.phoneNumbers('PN557ce644e5ab84fa21cc21112e22c485')
       .remove()
       .then(function(response) {
         console.log(response);
       }).catch(function(error) {
         console.log(error);
       });
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Messaging.V1.Service;


class Example
{
    static void Main (string[] args)
    {
      // Find your Account SID and Auth Token at twilio.com/console
      const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
      const string authToken = "your_auth_token";
      const string pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
      const string phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";

      TwilioClient.Init(accountSid, authToken);

      var deleted = PhoneNumberResource.Delete(pathServiceSid, phoneNumberSid);

      Console.WriteLine(deleted);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php'; // Loads the library

use Twilio\Rest\Client;

$account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$auth_token = 'your_auth_token';
$twilio = new Client($account_sid, $auth_token);

$phoneNumbers = $twilio->messaging->v1->services("MG2172dd2db502e20dd981ef0d67850e1a")
                                      ->phoneNumbers("PN557ce644e5ab84fa21cc21112e22c485")->delete();
# Get twilio-ruby from twilio.com/docs/libraries/ruby
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@deleted = @client.messaging.v1
  .services('MG2172dd2db502e20dd981ef0d67850e1a')
  .phone_numbers('PN557ce644e5ab84fa21cc21112e22c485')
  .delete

puts @deleted
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/console
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

did_delete = client.messaging \
                   .services(sid="MG2172dd2db502e20dd981ef0d67850e1a") \
                   .phone_numbers(sid="PN557ce644e5ab84fa21cc21112e22c485") \
                   .delete()

print(did_delete)
import com.twilio.Twilio;
import com.twilio.rest.messaging.v1.service.PhoneNumber;

public class Example {
    // Find your Account Sid and Token at twilio.com/console
    public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    public static final String AUTH_TOKEN = "your_auth_token";

    public static void main(String[] args) {
        // Initialize the client
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

        String pathServiceSid = "MG2172dd2db502e20dd981ef0d67850e1a";
        String phoneNumberSid = "PN557ce644e5ab84fa21cc21112e22c485";
        PhoneNumber.deleter(pathServiceSid, phoneNumberSid).delete();
    }
}
curl 'https://messaging.twilio.com/v1/Services/MG2172dd2db502e20dd981ef0d67850e1a/PhoneNumbers/PN557ce644e5ab84fa21cc21112e22c485' -X DELETE \
    -u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
{}