REST API: Subaccounts

Subaccounts in Twilio are just accounts that are "owned" by your account. Using a subaccount, you can segment each of your customers' use of Twilio and keep it separate from all the rest. This will allow you to easily manage the activity and resources of each customer independently.

Note: A master account can only have up to 1000 subaccounts by default. If you need more subaccounts please contact support.

Billing

Twilio bills all subaccount usage directly to your master account. You'll have one Twilio balance for all subaccounts. If your master Twilio account is ever suspended, your subaccounts will also be suspended.

Skip to calculate billing for subaccounts >>

Authentication

You can use your master Twilio Account credentials (AccountSid and AuthToken) to access Twilio's REST API for your master account as well as any of your subaccounts. You may also use a subaccount's AccountSid and AuthToken to access the resources of that subaccount. You can not use a subaccount's credentials to access the resources of your master Twilio account or any other subaccounts.

International

We are currently working on ways to help our customers minimize the risk of fraudulent international calls and provide ways for Twilio subaccounts to dial certain international destinations. If you have any questions, please contact support.

Permissions

Subaccounts use the master account's voice and SMS messaging permissions.

Creating Subaccounts

To create a new subaccount, make an HTTP POST request to your Accounts list resource URI:

/2010-04-01/Accounts

If successful, Twilio responds with a representation of the new Account resource.

POST Parameters

Optional Parameters

Your request to create a subaccount may include the following parameters:

Parameter Description
FriendlyName A human readable description of the new subaccount, up to 64 characters. Defaults to "SubAccount Created at {YYYY-MM-DD HH:MM meridian}".

The FriendlyName property is useful for organizing accounts and linking them back to information in your own system. For example, you may want to create subaccounts where the FriendlyName is the primary key of the customer in your application's database.

Example
Create a subaccount
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
SDK Version:
  • 4.x
  • 5.x
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$account = $client->accounts->create(
    array("friendlyName" => "Submarine")
);

echo $account->sid;
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts.json \
    -d "FriendlyName=Submarine" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

$account = $client->accounts->create(array(
        "FriendlyName" => "Submarine"
    ));
echo $account->sid;
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    
    var account = twilio.CreateSubAccount("Submarine");
    
    Console.WriteLine(account.Sid);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.AccountFactory;
import com.twilio.sdk.resource.instance.Account;
import com.twilio.sdk.resource.list.AccountList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the AccountList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("FriendlyName", "Submarine"));
    
    
    AccountFactory accountFactory = client.getAccountFactory();
    Account account = accountFactory.create(params);
    System.out.println(account.getSid());
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.accounts.create({
    friendlyName: "Submarine"
}, function(err, account) {
    process.stdout.write(account.sid);
});
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

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

account = client.accounts.create(friendly_name="Submarine")
print(account.sid)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

account = @client.accounts.create(:friendly_name => "Submarine")
puts account.friendly_name
Show Output
  • JSON
  • XML
{
    "sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "friendly_name": "Submarine",
    "auth_token": "redacted",
    "date_created": "Tue, 25 Jan 2011 19:24:40 +0000",
    "date_updated": "Tue, 25 Jan 2011 19:25:02 +0000",
    "status": "active",
    "subresource_uris": {
        "available_phone_numbers": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/AvailablePhoneNumbers.json",
        "calls": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json",
        "conferences": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Conferences.json",
        "incoming_phone_numbers": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers.json",
        "notifications": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Notifications.json",
        "outgoing_caller_ids": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/OutgoingCallerIds.json",
        "recordings": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings.json",
        "sandbox": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sandbox.json",
        "sms_messages": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages.json",
        "transcriptions": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcriptions.json"
    },
    "type": "Full",
    "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json"
}
<TwilioResponse>
  <Account>
	<Sid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</Sid>
	<FriendlyName>Submarine</FriendlyName>
	<Status>active</Status>
	<AuthToken>redacted</AuthToken>
	<DateCreated>Tue, 12 Jan 2010 04:41:09 +0000</DateCreated>
	<DateUpdated>Tue, 25 Jan 2011 07:24:36 +0000</DateUpdated>
	<Type>Full</Type>
	<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</Uri>
	<SubresourceUris>
	  <AvailablePhoneNumbers>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/AvailablePhoneNumbers</AvailablePhoneNumbers>
	  <Calls>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls</Calls>
	  <Conferences>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Conferences</Conferences>
	  <IncomingPhoneNumbers>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers</IncomingPhoneNumbers>
	  <Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Notifications</Notifications>
	  <OutgoingCallerIds>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/OutgoingCallerIds</OutgoingCallerIds>
	  <Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings</Recordings>
	  <Sandbox>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sandbox</Sandbox>
	  <SMSMessages>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages</SMSMessages>
	  <Transcriptions>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcriptions</Transcriptions>
	</SubresourceUris>
  </Account>
</TwilioResponse>

Getting Started with Subaccounts

Subaccounts are a great way to segment your Twilio usage and act on behalf of your customers, agents or employees.

If you are running a hosted service that relies on Twilio you can create a Twilio subaccount for each customer that signs up. Then if a customer closes his or her account with your service, you can simply deactivate the associated Twilio subaccount.

Subaccounts allow you to use the Twilio REST API just as you would for a single account; a subaccount can have its own phone numbers and caller IDs, applications and SIP Domains. You can manage a subaccount's calls, messagess, recordings, and transcriptions without affecting other subaccounts.

Finding Subaccounts

You can query any particular subaccount and its related resources via the REST API by AccountSid.

Return a subaccount resource by its account SID
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
SDK Version:
  • 4.x
  • 5.x
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$subAccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
$account = $client->accounts->getContext($subAccountSid)->fetch();

echo $account->status;
$ curl -G https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
$account = $client->accounts->get("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
echo $account->status;
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var account = twilio.GetAccount("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    
    Console.WriteLine(account.Status);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Account;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Get an object from its sid. If you do not have a sid,
    // check out the list resource examples on this page
    Account account = client.getAccount("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    System.out.println(account.getStatus());
    
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.accounts("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").get(function(err, account) {
    console.log(account.status);
});
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

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

account = client.accounts.get("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
print(account.status)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

# Get an object from its sid. If you do not have a sid,
# check out the list resource examples on this page
@account = @client.accounts.get("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
puts @account.status
Show Output
  • JSON
  • XML
{
    "sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "friendly_name": "MySubaccount",
    "auth_token": "redacted",
    "date_created": "Tue, 25 Jan 2011 19:24:40 +0000",
    "date_updated": "Tue, 25 Jan 2011 19:25:02 +0000",
    "status": "active",
    "subresource_uris": {
        "available_phone_numbers": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/AvailablePhoneNumbers.json",
        "calls": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json",
        "conferences": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Conferences.json",
        "incoming_phone_numbers": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers.json",
        "notifications": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Notifications.json",
        "outgoing_caller_ids": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/OutgoingCallerIds.json",
        "recordings": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings.json",
        "sandbox": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sandbox.json",
        "sms_messages": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages.json",
        "transcriptions": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcriptions.json"
    },
    "type": "Full",
    "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json"
}
<TwilioResponse>
  <Account>
	<Sid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</Sid>
	<FriendlyName>MySubaccount</FriendlyName>
	<Status>active</Status>
	<AuthToken>redacted</AuthToken>
	<DateCreated>Tue, 12 Jan 2010 04:41:09 +0000</DateCreated>
	<DateUpdated>Tue, 25 Jan 2011 07:24:36 +0000</DateUpdated>
	<Type>Full</Type>
	<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</Uri>
	<SubresourceUris>
	  <AvailablePhoneNumbers>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/AvailablePhoneNumbers</AvailablePhoneNumbers>
	  <Calls>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls</Calls>
	  <Conferences>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Conferences</Conferences>
	  <IncomingPhoneNumbers>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers</IncomingPhoneNumbers>
	  <Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Notifications</Notifications>
	  <OutgoingCallerIds>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/OutgoingCallerIds</OutgoingCallerIds>
	  <Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings</Recordings>
	  <Sandbox>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sandbox</Sandbox>
	  <SMSMessages>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages</SMSMessages>
	  <Transcriptions>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcriptions</Transcriptions>
	</SubresourceUris>
  </Account>
</TwilioResponse>

If you don't know the AccountSid of a subaccount but you know the FriendlyName, you can query your Accounts list resource with a FriendlyName query string filter:

Query subaccounts by friendly name
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
SDK Version:
  • 4.x
  • 5.x
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$accounts = $client->accounts->read(
    array("friendlyName" => "MySubaccount")
);
// Loop over the list of accounts and echo a property for each one
foreach ($accounts as $account) {
    echo $account->status;
}
$ curl -G https://api.twilio.com/2010-04-01/Accounts.json \
    -d "FriendlyName=MySubaccount" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

// Loop over the list of accounts and echo a property for each one
foreach ($client->accounts->getIterator(0, 50, array(
        "FriendlyName" => "MySubaccount"
    )) as $account
) {
    echo $account->status;
}
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;

class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var accounts = twilio.ListSubAccounts("MySubaccount");

    foreach (var account in accounts.Accounts)
    {
      Console.WriteLine(account.Status);
    }
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Account;
import com.twilio.sdk.resource.list.AccountList;
import java.util.HashMap;
import java.util.Map;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Build a filter for the AccountList
    Map<String, String> params = new HashMap<String, String>();
    
    params.put("FriendlyName", "MySubaccount");
    
    AccountList accounts = client.getAccounts(params);
    
    // Loop over accounts and print out a property for each one.
    for (Account account : accounts) {
      System.out.println(account.getStatus());
    }
    
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.accounts.list({ friendlyName: "MySubaccount" }, function(err, data) {
    data.accounts.forEach(function(account) {
        console.log(account.Status);
    });
});
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

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

# A list of account objects with the properties described above
accounts = client.accounts.list(friendly_name="MySubaccount")
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token


# Loop over accounts and print out a property for each one
@client.accounts.list({:friendly_name => "MySubaccount"}).each do |account|
    puts account.status
end
Show Output
  • JSON
  • XML
[{
    "sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "friendly_name": "MySubaccount",
    "auth_token": "redacted",
    "date_created": "Tue, 25 Jan 2011 19:24:40 +0000",
    "date_updated": "Tue, 25 Jan 2011 19:25:02 +0000",
    "status": "active",
    "subresource_uris": {
        "available_phone_numbers": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/AvailablePhoneNumbers.json",
        "calls": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json",
        "conferences": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Conferences.json",
        "incoming_phone_numbers": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers.json",
        "notifications": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Notifications.json",
        "outgoing_caller_ids": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/OutgoingCallerIds.json",
        "recordings": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings.json",
        "sandbox": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sandbox.json",
        "sms_messages": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages.json",
        "transcriptions": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcriptions.json"
    },
    "type": "Full",
    "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json"
}]
<TwilioResponse>
  <Accounts>
	<Account>
		<Sid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</Sid>
		<FriendlyName>MySubaccount</FriendlyName>
		<Status>active</Status>
		<AuthToken>redacted</AuthToken>
		<DateCreated>Tue, 12 Jan 2010 04:41:09 +0000</DateCreated>
		<DateUpdated>Tue, 25 Jan 2011 07:24:36 +0000</DateUpdated>
		<Type>Full</Type>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</Uri>
		<SubresourceUris>
		  <AvailablePhoneNumbers>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/AvailablePhoneNumbers</AvailablePhoneNumbers>
		  <Calls>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls</Calls>
		  <Conferences>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Conferences</Conferences>
		  <IncomingPhoneNumbers>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers</IncomingPhoneNumbers>
		  <Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Notifications</Notifications>
		  <OutgoingCallerIds>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/OutgoingCallerIds</OutgoingCallerIds>
		  <Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings</Recordings>
		  <Sandbox>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Sandbox</Sandbox>
		  <SMSMessages>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/SMS/Messages</SMSMessages>
		  <Transcriptions>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Transcriptions</Transcriptions>
		</SubresourceUris>
	</Account>
  </Accounts>
</TwilioResponse>

Making a phone call with a Subaccount

In order to make calls and send messages using a subaccount you simply need to replace the account credentials with the subaccount credentials.

SDK Version:
  • 4.x
  • 5.x
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sAsid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$sAtoken = "your_auth_token";
$sAClient = new Client($sAsid, $sAtoken);

$sAClient->account->calls->create(
    '+16518675309', // The visitor's phone number
    '+14158141829', // A Twilio number in your subaccount
    array(
        "url" => 'http://twimlets.com/message?Message%5B0%5D=Hello%20from%20your%20subaccount'
    )
);
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'twilio-ruby'

# Account Sid and Auth token for your new subaccount
sub_account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
sub_auth_token = 'your_auth_token'
@sub_account_client = Twilio::REST::Client.new(sub_account_sid, sub_auth_token)

# Make a call from your subaccount
@sub_account_client.account.calls.create(
  from: '+14158141829',
  to:   '+16518675309',
  url:  'http://twimlets.com/message?Message%5B0%5D=Hello%20from%20your%20subaccount'
)
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Account Sid and Auth token for your new subaccount
$sa_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$sa_token = "your_auth_token";
$sa_client = new Services_Twilio($sa_sid, $sa_token);

$sa_client->account->calls->create(
    '+14158141829', // A Twilio number in your subaccount
    '+16518675309', // The visitor's phone number
    'http://twimlets.com/message?Message%5B0%5D=Hello%20from%20your%20subaccount'
);

Calculate billing for Subaccount usage

In many cases you may want to calculate the billing incurred by a subaccount. Let's say you created a subaccount for a customer and you needed to charge them for their monthly usage.

This is how you would calculate how many minutes of calling your customer made over the last 30 days:

SDK Version:
  • 4.x
  • 5.x
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

// Place to store the billable usage
$timeToBill = 0;

// 30 days ago
$date = strtotime('-1 month');

$calls = $client->account
    ->calls
    ->read(
        array("startTime" => date('Y-m-d', $date))
    );

foreach ($calls as $call) {
    // Get time of call in minutes
    $timeToBill += ceil((float) $call->duration);
}

echo "Account $sid used $timeToBill minutes.";
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'twilio-ruby'

# Account Sid and Auth token for your new subaccount
sub_account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
sub_auth_token = 'your_auth_token'
@sub_account_client = Twilio::REST::Client.new sub_account_sid, sub_auth_token
@subaccount = @sub_account_client.account

# Place to store the billable usage
time_to_bill = 0

# 30 days ago
start_time = Time.now - ( 30 * 24 * 60 * 60 )

# Get all calls for the last 30 days
@subaccount.calls.list({:page => 0, :page_size => 1000, :start_time => ">#{start_time.strftime('%Y-%m-%d')}"}).each do |call|
  # Get time of call in minutes
  time_to_bill += (call.duration.to_f/60).ceil
end

puts "Account #{sub_account_sid} used #{time_to_bill} minutes."
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Account Sid and Auth token for your new subaccount
$sa_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$sa_token = "your_auth_token";
$sa_client = new Services_Twilio($sa_sid, $sa_token);
$subaccount = $sa_client->account;

// Place to store the billable usage
$time_to_bill = 0;

// 30 days ago
$date = strtotime('-1 month');

// Get all calls for the last 30 days
$callIterator = $sa_client->account->calls->getIterator(
    0,
    1000,
    array(
        "StartTime" => date('Y-m-d', $date)
    )
);

foreach ($callIterator as $call) {
    // Get time of call in minutes
    $time_to_bill += ceil((float) $call->duration);
}

echo "Account $sa_sid used {$time_to_bill} minutes.";

Suspending a Subaccount

While an account is suspended it cannot make or receive phone calls or send and receive SMS messages. This is useful when your customer does not pay their bill and you want to suspend their account until a successful payment is received. However, you will be charged monthly for any phone numbers the subaccount owns.

Simply POST the parameter 'Status' with the value 'suspended' to suspend an account.

To reactivate a suspended subaccount, just POST the value 'active' for the 'Status' parameter and we will restore the account to full service.

For details and an example, see the Account instance resource POST section.

Note that you must use your master account's authentication credentials to suspend a subaccount. Also you cannot suspend your master account.

Closing a Subaccount

If your customer closes his or her account with you, you can permanently close the associated Twilio subaccount by POSTing the parameter 'Status' with the value 'closed' to the subaccount resource URI.

When you close a subaccount, Twilio will release all phone numbers assigned to it and shut it down completely. You can't ever use a closed account to make and receive phone calls or send and receive SMS messages. It's closed, gone, kaput. It will still appear in your accounts list, and you will still have access to historical data for that subaccount, but you cannot reopen a closed account.

For details and an example, see the Account instance resource POST section.

Note that you must use your master account's authentication credentials to close a subaccount. You also cannot close your master account.

Exchanging Phone Numbers Between Accounts

You can transfer numbers between subaccounts, and between your master account and any one of your subaccounts. You must use your master account's credentials when making the API request to transfer a phone number.

To transfer a phone number between two accounts that you control, make an HTTP POST request to an IncomingPhoneNumber instance resource URI. In the body of the POST set the parameter 'AccountSid' to the AccountSid of the account you wish to own that number. This will remove the phone number from its original account and make it available under the IncomingPhoneNumbers list resource of the new account while retaining all other properties.

If any of the phone numbers you would like to transfer have Address Requirements, you will need to create a compliant Address in the new subaccount before transferring the phone number.

Remember, closing a subaccount as described above will release all of that account's phone numbers, so you might consider transferring all numbers to your master account beforehand if you want to keep them.

Example

Transfer a phone number from account AC00000000000000000000000000000001 to AC00000000000000000000000000000002:

Transfer phone numbers between accounts
  • C#
  • Java
  • Node.js
  • PHP
  • Python
  • Ruby
  • curl
SDK Version:
  • 4.x
  • 5.x
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$firstAccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$secondAccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
$number = $client->accounts->getContext($firstAccountSid)
    ->incomingPhoneNumbers("PN2a0747eba6abf96b7e3c3ff0b4530f6e")
    ->update(
        array("accountSid" => $secondAccountSid)
    );

echo $number->phoneNumber;
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers/PN2a0747eba6abf96b7e3c3ff0b4530f6e.json \
    -d "AccountSid=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
$token = "your_auth_token"; 
$client = new Services_Twilio($sid, $token);

// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
$number = $client->accounts->get("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
    ->incoming_phone_numbers->get("PN2a0747eba6abf96b7e3c3ff0b4530f6e");
$number->update(array(
    "AccountSid" => "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
));
echo $number->phone_number;
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example 
{
  static void Main(string[] args) 
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    string CurrentAccount = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    var twilio = new TwilioRestClient(AccountSid, AuthToken, CurrentAccount);

    var options = new PhoneNumberOptions();
    options.AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    
    twilio.UpdateIncomingPhoneNumber("PN2a0747eba6abf96b7e3c3ff0b4530f6e", options);
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.IncomingPhoneNumber;
import com.twilio.sdk.resource.list.IncomingPhoneNumberList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Example { 

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String ORIGINAL_ACCT = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Get an object from its sid. If you do not have a sid,
    // check out the list resource examples on this page
    IncomingPhoneNumber number = client.getAccount(ORIGINAL_ACCT)
      .getIncomingPhoneNumber("PN2a0747eba6abf96b7e3c3ff0b4530f6e");
    // Build a filter for the IncomingPhoneNumberList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("AccountSid", "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"));
    number.update(params);
    
  }
}
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = 'your_auth_token';
var client = require('twilio')(accountSid, authToken);

var phoneNumber = client.accounts('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
    .incomingPhoneNumbers('PN2a0747eba6abf96b7e3c3ff0b4530f6e');

phoneNumber.update({
    accountSid: "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}, function(err, number) {
    console.log(number);
});
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)
new_sub_account = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
number_sid = "PN2a0747eba6abf96b7e3c3ff0b4530f6e"

number = client.phone_numbers.update(number_sid, account_sid=new_sub_account)
print(number.phone_number)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token
 
@subaccount = @client.accounts.get("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
@number = @subaccount.incoming_phone_numbers.get("PN2a0747eba6abf96b7e3c3ff0b4530f6e")
@number.update(:account_sid => "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
puts @number.phone_number
Show Output
  • JSON
  • XML
{
	"sid": "PN2a0747eba6abf96b7e3c3ff0b4530f6e",
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"friendly_name": "My Company Line",
	"phone_number": "+15105647903",
	"voice_url": "http://demo.twilio.com/docs/voice.xml",
	"voice_method": "POST",
	"voice_fallback_url": null,
	"voice_fallback_method": "POST",
	"voice_caller_idlookup": null,
	"date_created": "Mon, 16 Aug 2010 23:00:23 +0000",
	"date_updated": "Mon, 16 Aug 2010 23:00:23 +0000",
	"sms_url": null,
	"sms_method": "POST",
	"sms_fallback_url": null,
	"sms_fallback_method": "GET",
	"capabilities": {
		"voice": null,
		"sms": null
	},
	"status_callback": null,
	"status_callback_method": null,
	"api_version": "2010-04-01",
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/IncomingPhoneNumbers\/PN2a0747eba6abf96b7e3c3ff0b4530f6e.json"
}
<TwilioResponse>
	<IncomingPhoneNumber>
		<Sid>PN2a0747eba6abf96b7e3c3ff0b4530f6e</Sid>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<FriendlyName>My Company Line</FriendlyName>
		<PhoneNumber>+15105647903</PhoneNumber>
		<VoiceUrl>http://demo.twilio.com/docs/voice.xml</VoiceUrl>
		<VoiceMethod>POST</VoiceMethod>
		<VoiceFallbackUrl/>
		<VoiceFallbackMethod>POST</VoiceFallbackMethod>
		<VoiceCallerIdLookup>false</VoiceCallerIdLookup>
		<DateCreated>Mon, 16 Aug 2010 23:00:23 +0000</DateCreated>
		<DateUpdated>Mon, 16 Aug 2010 23:00:23 +0000</DateUpdated>
		<SmsUrl/>
		<SmsMethod>POST</SmsMethod>
		<SmsFallbackUrl/>
		<SmsFallbackMethod>GET</SmsFallbackMethod>
		<Capabilities>
			<Voice>true</Voice>
			<SMS>true</SMS>
		</Capabilities>
		<StatusCallback/>
		<StatusCallbackMethod/>
		<ApiVersion>2010-04-01</ApiVersion>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/IncomingPhoneNumbers/PN2a0747eba6abf96b7e3c3ff0b4530f6e</Uri>
	</IncomingPhoneNumber>
</TwilioResponse>