Rate this page:

Twilio CLI Examples

Create and send an SMS message

twilio api:core:messages:create \
  --to +12127363100 \
  --from +14155551212 \
  --body "Ahoy" \
  -o json

Look up a phone number’s carrier and caller name

twilio api:lookups:v1:phone-numbers:fetch \
  --phone-number +12127363100 \
  --type carrier \
  --type caller-name \
  -o json

List phone numbers available for purchase by area code

twilio api:core:available-phone-numbers:local:list \
  --area-code="209" --country-code US

Purchase an available phone number

twilio api:core:incoming-phone-numbers:create \

Review your phone numbers with a filter

twilio api:core:incoming-phone-numbers:list \

Have your phone number respond to an incoming SMS message

twilio api:core:incoming-phone-numbers:update \
  --sid PNfbe7ed1d730e425d0db746c24f7d443c \
  --sms-url ""

List the messages your number has received

twilio api:core:messages:list --to="+12095551212"

List the messages your number has received, including the body

twilio api:core:messages:list \
  --to="+12095551212" \

Send a Twilio SendGrid email with TSV-format message logs attached

Set the SENDGRID_API_KEY environment variable with a SendGrid API key.


twilio api:core:messages:list \
  -o tsv \
  | twilio email:send \
  --to ''\
  --from ''\
  --subject='Message log'\
  --text 'Message log'

Transfer a phone number between accounts

In this example we’ll transfer a phone number from the main account to subaccount 1, then to subaccount 2, then back to the main account. First, set a few environment variables to better identify the various accounts:

export MAIN_ACCOUNT_SID="AC00000000000000000000000000000000"
export SUBACCOUNT_1_SID="AC11111111111111111111111111111111"
export SUBACCOUNT_2_SID="AC22222222222222222222222222222222"

Assuming you are using a main account profile in the CLI and the phone number is owned by the main account, transfer the phone number to subaccount 1:

twilio api:core:incoming-phone-numbers:update \
  --target-account-sid $SUBACCOUNT_1_SID

The --account-sid flag is not required — this is because the account SID defaults to the CLI profile account SID.

Now transfer the phone number from subaccount 1 to subaccount 2:

twilio api:core:incoming-phone-numbers:update \
  --account-sid $SUBACCOUNT_1_SID \
  --target-account-sid $SUBACCOUNT_2_SID

Finally, transfer the phone number from subaccount 2 to the main account:

twilio api:core:incoming-phone-numbers:update \
  --account-sid $SUBACCOUNT_2_SID \
  --target-account-sid $MAIN_ACCOUNT_SID

In the last two commands the --account-sid flag is required as the phone number is not owned by the main account.

List most recent debugger logs

twilio debugger:logs:list
Rate this page:

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 by visiting Twilio's Community Forums or browsing the Twilio tag on Stack Overflow.


        Thank you for your feedback!

        We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        Step 1

        Get link

        Get a free personal referral link here

        Step 2

        Give $10

        Your user signs up and upgrade using link

        Step 3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more