Subaccounts in Twilio are accounts that are "owned" by your main
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 manage the activity and resources of each customer
independently.
(warning)
Important Notes
A main account can only have up to 1000 subaccounts by default. If you need more subaccounts, please
contact support
.
By default, closed subaccounts will be automatically deleted 30 days after closure.
Billing
Twilio bills all subaccount usage directly to your main account. You'll
have one Twilio balance for all subaccounts. If your main Twilio
account is ever suspended, your subaccounts will also be
suspended.
You can use your main account credentials (AccountSid and AuthToken) to access Twilio's REST API for your main account, as well as v2010 API resources for 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 main Twilio account or any other subaccounts.
If you're authenticating the helper libraries, pass in your main Account SID and main Auth Token as the first two credentials, and the appropriate Subaccount SID as the third parameter.
(error)
Danger
When performing CRUD operations within a subaccount, use the subaccount SID and auth token. Alternatively, you can generate API Keys at the subaccount level for authentication.
(warning)
Warning
Main account API Keys are only available to access main account resources. Access to subaccount resources will be denied.
(warning)
Warning
Your main account credentials will allow you to access resources for any of your subaccounts that fall under the v2010 REST API. However, resources on subdomains, such as studio.twilio.com and taskrouter.twilio.com, must be accessed directly using subaccount credentials (API Keys or subaccount SID + subaccount auth token).
There are many ways to determine if a resource lives on its own subdomain or under v2010. One example method is to find the API Reference page for the resource, such as the Workspace resource. Observe the returned URL value in the example payloads: if the URL begins with https://SOME-SUBDOMAIN.twilio.com, then you must access that resource using subaccount-specific credentials. If you do the same for some other resource, such as the Messaging resource, and see that URI begins with /2010-04-01, then it can be safely accessed using either your main account or subaccount credentials.
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 main 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:
_10
/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:
A human readable description of the account to create, defaults to SubAccount Created at {YYYY-MM-DD HH:MM meridian}
{"FriendlyName":"friendly_name"}
The FriendlyName property is useful for organizing accounts and linking them
back to information in your 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
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
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 their account with your
service, you can 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 phone numbers and
caller IDs, applications and SIP Domains. You can manage a subaccount's
calls, messages, 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
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
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
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
In order to send messages using a subaccount, use the subaccount's Account SID and Auth Token when making your request to Twilio's Programmable Messaging API.
Send a message from a subaccount
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl
_21
// Download the helper library from https://www.twilio.com/docs/node/install
_21
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_21
_21
// Find your Account SID and Auth Token at twilio.com/console
_21
// and set the environment variables. See http://twil.io/secure
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 usage.
You can iterate over all of the calls and sum up the product of price and duration.
The example below shows the API request to fetch all Calls that began on January 15, 2018. In the response, each object in the calls array contains a price property.
Note: In this example, the StartTime parameter returns calls only that began on January 15, 2018. You can also use inequalities (e.g. <= and >=) and the EndTime parameter to fetch all Calls from a specific date span. Learn more on the Call Resource API Reference page.
Calculate billing for subaccount usage
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
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.
To suspend a subaccount, POST the parameter 'Status' with the value 'suspended' to suspend an
account.
(warning)
Warning
Note that in-progress calls will not automatically end when a subaccount is suspended. This must be done manually by changing the status of these calls to completed.
Suspend a Subaccount
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
Note that you must use your main account's authentication credentials to suspend a subaccount. You cannot suspend your main account.
Closing a Subaccount
If your customer closes their 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.
Permanently Close a Subaccount
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
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 - you cannot reopen a closed account.
Your closed subaccount will still appear in your accounts list, and you will still have access
to historical data for that subaccount, unless automatic deletion of closed subaccounts is enabled.
If you have enabled automatic deletion of closed subaccounts through the Subaccounts settings page, we will delete all subaccount data 30 days after closure including previously closed subaccounts and those subaccounts will no longer appear on the Console.
Twilio has enabled this setting for all accounts created after July 5, 2018, and for all accounts without subaccounts
For all other accounts, account owners can turn this setting on through the
Subaccounts
settings page.
(warning)
Warning
Note that you must use your main account's authentication credentials to close a subaccount. You also cannot close your main account.
Exchange Phone Numbers Between Accounts
(information)
WhatsApp Activated Numbers
If you have a WhatsApp Sender connected to your phone number, it will not be moved to the gaining account SID. To move phone numbers connected to WhatsApp Senders, open a support ticket to move the WhatsApp Sender before moving the phone number.
You can transfer numbers between subaccounts, and between your main account
and any one of your subaccounts. You must use your main 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.
Number configurations may need to be reconfigured.
Any Toll-Free number verifications, A2P registrations or Trust Hub enrollments will need to be resubmitted and reconfigured.
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 main account beforehand if you want to keep them.
Example
Transfer a phone number from your primary account AC00000000000000000000000000000001 to
subaccount AC00000000000000000000000000000002:
Transfer phone numbers from primary account to subaccount
Node.js
Python
C#
Java
PHP
Ruby
twilio-cli
curl
_10
// Download the helper library from https://www.twilio.com/docs/node/install
_10
// Your Account Sid and Auth Token from twilio.com/console
_10
// To set up environmental variables, see http://twil.io/secure