The Twilio CLI also features support for issuing commands tied to subaccounts. Subaccounts are commonly created to separate usage by team, product, customer, and more.
Some examples of "non-core" commands are:
Below are the two methods for issuing commands tied to a subaccount.
To make all subsequent CLI commands via the intended subaccount:
Set the subaccount's profile as active
_10twilio profiles:use SUBACCOUNT_PROFILE_ID
Issue commands as usual. Commands will use the active subaccount's credentials
You can apply the subaccount to individual commands by using the
_10twilio phone-numbers:list -p SUBACCOUNT_PROFILE_ID
Refer to the profiles documentation for more information about profiles and profile management.
Core API commands are any CLI command that reference resources under the V2010 API (
twilio api:core:.*), such as
Profiles created for parent accounts cannot be used to manage subaccounts, as the
twilio login process creates a Standard API Key. An appropriate Main API Key is necessary to work with subaccounts, and can be created here.
You must use environment variables if you want access to subaccounts for this family of commands. There are two options: use a Main API Key, or the Parent Account SID and Auth Token.
Once you have your subaccount SID, you can add the
--account-sid parameter to a command to reference a specific subaccount, provided it's a
twilio api:core command.
_10$ export TWILIO_ACCOUNT_SID=ACXXXXXXXX_10$ export TWILIO_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXX_10$ export TWILIO_API_SECRET=XXXXXXXXXXXXXXXXXXXXXXXXXXXX_10$ twilio api:core:available-phone-numbers:local:list \_10--area-code="415" \_10--country-code US \_10--account-sid=SUBACCOUNT_SID
In the rare case that you cannot create an API Key or do not have access to one, you can leverage the Account SID and Auth Token of the subaccount's parent account as environment variables for authorization.
The Account SID and Auth Token can be retrieved from the console.
_10$ export TWILIO_ACCOUNT_SID=ACXXXXXXXX_10$ export TWILIO_AUTH_TOKEN=XXXXXXXXXXXXXXXXXXXXXXXXXXXX_10$ twilio api:core:available-phone-numbers:local:list \_10--area-code="415" \_10--country-code US \_10--account-sid=SUBACCOUNT_SID
Using this method is highly discouraged as it increases the risk of exposing your Auth Token.