Subaccounts
Subaccounts possess their own resources, such as phone numbers, yet they are managed under a primary Twilio account with which they share a financial balance. This page should help you get started.
Twilio Subaccounts Management
Subaccounts can be created and accessed via Console, but can also be managed via the Twilio REST API. For more details, please see our article View and Create New Twilio Subaccounts.
For each subaccount you will need the following:
Subaccount Sid
API key & Secret
Voice Application
Caller number: make sure the number uses the main account calling function
Following we will explain more how to manage your subaccounts using Twilio Console.
Create a subaccount:
To create a subaccount go to the console > subaccounts > Create
If you are using the console, make sure to switch to the subaccount before implementing the following steps
Create a subaccount API key:
Make sure you are using the subaccount console, then follow the same steps as create an API key
Create a subaccount voice application:
Make sure you are using the subaccount console, then follow the same steps as Create a voice application. Regarding the application voice function, you can use the main account voice function for easier maintenance. How ever you can create functions for each account, if you have a special use case.
Bubble Editor
Step1: Access token generation
Create a custom event this event then Add an action that requests a subaccount voice access token and store the value in a state
Step 2: Adding token to the client
Provide the token to the client element by referring to the token state
Step 3: Refreshing Client Tokens Before Expiration
To ensure uninterrupted service, it's crucial to refresh client tokens before they expire. Implement a token refresh mechanism by triggering a custom event, get-token
, upon detecting that the current token is nearing expiration. Here's how to set up the event trigger:
Detect Token Expiration: By adding the token expiring element event
Trigger Custom Event: Add the
get-token
action. This action should request a new token and update the token state.
By following these steps, you can ensure your application maintains secure and continuous access to resources by keeping client tokens up to date.
Making a subaccount call
Similar to the making calls, just make sure to use a Caller number that's registered under the subaccount.
Receiving a subaccount incoming call
That can be implemented in two ways:
Using one voice function and adding the voice function URL to all the numbers under this account
Using Twilio Studio flow; Similar to the receiving calls, just make sure to do it form the subaccount console.
Last updated