メニュー

Expand
ページを評価:

Command-Line Interface (CLI) Quickstart

ベータ

This Twilio product is currently available as a beta release. Some features are not yet implemented and others may be changed before the product is declared as Generally Available. Beta products are not covered by a Twilio SLA. Learn more about beta product support.

twilio-cli allows you to manage your Twilio resources from your terminal or command prompt. Let’s get it installed and take a quick tour. Follow the installation instructions for your specific platform below.

Install twilio-cli

We strongly discourage installing twilio-cli using a combination of methods. For example, installing twilio-cli using both Homebrew and npm can cause conflicts in your PATH that may result in unexpected behavior from commands and/or difficulty updating twilio-cli.

Install using Homebrew

The suggested way to install twilio-cli on macOS is to use Homebrew. If you don't already have it installed, visit the Homebrew site for installation instructions and then return here.

Once you have installed Homebrew, run the following command to install twilio-cli:

brew tap twilio/brew && brew install twilio

Install using the official .pkg file

Another way to install twilio-cli is by using the standard macOS user interface and your browser:

  1. In your browser, download the latest macOS installation file.
  2. Run the downloaded file and follow the on-screen instructions.

To install a specific version of twilio-cli, find your desired version on the releases page, download the respective .pkg file under that release's Assets, and run the file.

Verify your installation

To confirm the installation, open a command prompt window (using an app such as Terminal or iTerm) and use:

$ twilio --version
twilio-cli/3.0.0 darwin-x64 node-v16.13.1

You should see twilio-cli/x.y.z in the output. If you don’t but you have installed twilio-cli, you may need to restart the command prompt window.

Update twilio-cli

Homebrew

If you installed twilio-cli with brew and want to upgrade to the latest version, run:

brew upgrade twilio

macOS

If you installed using a .pkg file, you will need to download and run a new installer each time you wish to update your current installation of twilio-cli. To check the latest version and when it was released, see the twilio-cli Release Log on GitHub.

Uninstall twilio-cli

Homebrew

If you installed twilio-cli using Homebrew, you can uninstall twilio-cli by using:

brew uninstall twilio

macOS

If you installed twilio-cli using a .pkg file, you can uninstall it by using:

/usr/local/lib/twilio-cli/bin/uninstall

Note This command may require sudo to execute successfully

Install using Scoop

The suggested way to install twilio-cli is by using Scoop, a command-line installer for Windows. If you don't already have it installed, visit the Scoop site for installation instructions and then return here.

Note PowerShell will need to be run as an administrator to avoid common permission issues when installing via Scoop

  1. Add the twilio-cli Bucket:
    scoop bucket add twilio-scoop https://github.com/twilio/scoop-twilio-cli​
  2. Install the app:
    scoop install twilio​

Install using the official .exe file

Another way to install twilio-cli is by using the standard Windows user interface and your browser:

  1. In your browser, download the latest Windows installation file.
  2. Run the downloaded file and follow the on-screen instructions.

To install a specific version of twilio-cli, find your desired version on the releases page, download the respective .exe file under that release's Assets, and run the file.

Verify your installation

To confirm the installation, open a command prompt window (using an app such as PowerShell) and use the twilio –version command:

$ twilio --version
twilio-cli/3.0.0 Windows/10 exe/AMD64

You should see twilio-cli/x.y.z in the output. If you don’t but you have installed twilio-cli, you may need to restart the command prompt window.

Update twilio-cli

Scoop

If you installed using Scoop:

  1. Check for available updates using:
    scoop status​
  2. If available, install the updates using:
    scoop update​

.exe

If you installed using an .exe file, you will need to download and run a new installer each time you wish to update your current installation of twilio-cli. To see the latest version and when it was released, see the twilio-cli Release Log on GitHub.

Uninstall twilio-cli

Scoop

To uninstall twilio-cli if you installed using Scoop, use:

scoop uninstall twilio

.exe

If you installed twilio-cli using the downloaded .exe file, follow these steps to uninstall:

  1. ​​Click Start > Control Panel > Programs > Programs and Features.
  2. Select twilio-cli, and then click Uninstall.

Install using apt

twilio-cli can be installed using the Advanced Package Tool (apt) on most distributions such as Debian, Ubuntu, Linux Mint, and more.

To do so, run the following commands in your terminal:

wget -qO- https://twilio-cli-prod.s3.amazonaws.com/twilio_pub.asc \
  | sudo apt-key add -
sudo touch /etc/apt/sources.list.d/twilio.list
echo 'deb https://twilio-cli-prod.s3.amazonaws.com/apt/ /' \
  | sudo tee /etc/apt/sources.list.d/twilio.list
sudo apt update
sudo apt install -y twilio

Install using the official .deb file

As an alternative, you may also install twilio-cli using apt and a local .deb file:

  1. In your browser, download the latest .deb file.
  2. Install the downloaded package using apt:
    apt install /path/to/file.deb​

To install a specific version of twilio-cli, find your desired version on the releases page, download the respective .deb file under that release's Assets, and use that file in the command above.

Install using the official .rpm file (Red Hat-based distros)

twilio-cli can also be installed using package managers for Red Hat-based Linux distributions, primarily yum and dnf:

  1. In your browser, download the latest RPM package.
  2. Install the downloaded package using the package manager of your choice, for example:
    yum install /path/to/package.rpm
    # or
    dnf install /path/to/package.rpm
    

To install a specific version of twilio-cli, find your desired version on the releases page, download the respective .rpm file under that release's Assets, and use that file in the yum or dnf command above.

Verify your installation

To confirm the installation, open a command prompt window and use the twilio –version command:

$ twilio --version
twilio-cli/3.0.0 linux-x64 node-v16.13.1

You should see twilio-cli/x.y.z in the output. If you don’t but you have installed twilio-cli, you may need to restart the command prompt window.

Update twilio-cli

apt

If you installed twilio-cli with apt, you can upgrade using:

sudo apt update && sudo apt upgrade twilio

If you installed using a local .deb file, you will need to download and install the latest file each time you wish to update your current installation of twilio-cli. To see the latest version and when it was released, see the twilio-cli Release Log on GitHub.

.rpm

If you installed using a downloaded .rpm file, use:

yum update twilio
# or
dnf update twilio

The official Docker image for twilio-cli provides isolation, portability, and security that Twilio directly supports and maintains. This enables you to use twilio-cli in a container-based environment without having to manage the installation yourself.

Before you begin

In order to utilize the twilio-cli Docker image, you will need to make sure you have Docker installed and running on your system. For installation instructions, see the Docker website.

Run the Docker image

To run the twilio-cli Docker image with an interactive bash shell, use:

docker run -it --rm twilio/twilio-cli bash

Once the container has finished downloading and you have entered the shell, you can issue commands using twilio-cli. For example:

$ docker run -it --rm twilio/twilio-cli bash

root@6f645f0ba383:/twilio# twilio profiles:list
ID      Account SID                         Active
you     ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  true
main    ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  false

Run commands directly

It is also possible to pass commands directly to the Docker image for single, contained operations. For example, you can check the running version of twilio-cli with the following:

$ docker run -it --rm twilio/twilio-cli twilio --version​
twilio-cli/3.0.0 linux-x64 node-v14.18.1

Provide credentials and configuration

Since the container is cleaned up between each execution, it is useful to pass credentials and configuration directly to the Docker container instead of needing to use twilio login on each run.

Via environment variables

If you have your profile credentials set as environment variables, you can pass them directly to the Docker container. The environment variables will be picked up by the containerized version of twilio-cli:

$ export TWILIO_ACCOUNT_SID=...
$ export TWILIO_API_KEY=...
$ export TWILIO_API_SECRET=...
$ docker run -it --rm \
  -e TWILIO_ACCOUNT_SID \
  -e TWILIO_API_KEY \
  -e TWILIO_API_SECRET \
  twilio/twilio-cli twilio phone-numbers:list

SID                                 Phone Number  Friendly Name
PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  +15558675310  (555) 867-5310

See the Docker run reference guide for more information about setting container environment variables.

Via file system

Since twilio-cli stores your profile settings on your local file system, it's possible to share those settings with the Docker container by using Volumes. Your profiles will be inherited by the Docker container, without the need to login.

To share your local configuration with the Docker container, mount your system's ~/.twilio-cli directory to the container at /root/twilio-cli using the -v flag. See the Docker run reference guide for more information about the -v flag.

On macOS and Linux, use:

$ docker run -it --rm \
  -v ~/.twilio-cli:/root/.twilio-cli \
  twilio/twilio-cli twilio phone-numbers:list

SID                                 Phone Number  Friendly Name
PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  +15558675310  (555) 867-5310

Similarly, in Windows with PowerShell, you would run:

C:\> docker run -it --rm `
  -v $env:userprofile\.twilio-cli:/root/.twilio-cli `
  twilio/twilio-cli twilio phone-numbers:list

SID                                 Phone Number  Friendly Name
PNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  +15558675310  (555) 867-5310

Note If this fails to find your credentials, they are probably in a deprecated format from twilio-cli v2. To migrate your credentials, run twilio profiles:port and reattempt the above example.

Run a specific version or tag

There are multiple versions of the twilio-cli Docker image that you can use. To run a specific version, append the desired tag to your docker run command.

There are two types of tags:

  • latest - Sets the latest version of the Docker image, which we recommend. This is the default behavior of docker run, but you can choose to append it explicitly.
    docker run -it --rm twilio/twilio-cli:latest​ bash
  • <major.minor.patch> - Sets the container to run using a specific version of the Docker image.
    docker run -it --rm twilio/twilio-cli:2.36.1 bash​

Update to the latest Docker image

The latest Docker image is only downloaded to your machine on the first execution of docker run. You need to manually pull the latest version of subsequent runs if you wish to use an updated image.

To download the latest Docker image and make it available locally, use:

docker pull twilio/twilio-cli

Disclaimer

It’s strongly recommended to use one of the other installation methods if possible.

This installation method does not auto-update, and it uses your system’s version of Node.js, which may be older than the version Twilio develops twilio-cli against.

Install using npm

twilio-cli is also installable via npm. This is a manual install method that can be used in environments where auto-updating is not ideal, or where we do not offer a prebuilt binary, and requires that Node.js and npm be installed already on your machine. (npm is installed along with Node.js)

To globally install twilio-cli so that it can be used from any directory, use:

npm install -g twilio-cli

To update your CLI installation, use:

npm install -g twilio-cli@latest

Login to your Twilio account

In order to access your Twilio account, you need to provide your Twilio credentials to twilio-cli. This can be done by running this command:

twilio login

You will be prompted for your Account SID and Auth Token, both of which you can find on the dashboard of your Twilio console. This will create an API Key for you that will be stored securely for future use. Visit general usage to learn more about using multiple profiles.

Install CLI autocomplete (bash or zsh only)

If you are running bash or zsh on macOS or Linux, you can run one of the two commands below (as appropriate for the shell you are using):

twilio autocomplete bash

または

twilio autocomplete zsh

Follow the instructions provided to install command auto-complete for twilio-cli into your shell.

Make sure you restart or open a new shell after you complete the step to install autocomplete.

Exploring twilio-cli

The best way to learn about what you can do with twilio-cli is to simply run the command:

twilio

When you do, you will get a list of the various topics and commands you can run. Topics are just groupings for more topics and commands, just like the folder structure on your file system.

$ twilio
Unleash the power of Twilio from your command prompt. Visit https://twil.io/cli for documentation.

VERSION
  twilio-cli/3.0.0 darwin-x64 node-v16.13.1

USAGE
  $ twilio [COMMAND]

TOPICS
  api            advanced access to all of the Twilio APIs
  config         manage Twilio CLI configurations
  debugger       Show a list of log events generated for the account
  email          sends emails to single or multiple recipients using Twilio SendGrid
  feedback       provide feedback to the CLI team
  phone-numbers  manage Twilio phone numbers
  plugins        list available plugins for installation
  profiles       manage credentials for Twilio profiles

COMMANDS
  autocomplete  display autocomplete installation instructions
  feedback      provide feedback to the CLI team
  help          display help for twilio
  login         create a new profile to store Twilio Account credentials and configuration
  plugins       list installed plugins
  update        update the twilio CLI

See something that looks interesting? Just try running it:

twilio api

Since api is a topic, you will actually be shown more topics and commands that are contained within that topic. Let’s say in the process of exploring, you stumbled upon this command:

twilio api:core:messages:list

If you run that command, it will list all of your SMS messages, which may be a lot. How can you filter them? Or, more generally, how can you discover what options a given CLI command provides? The answer is to add --help to the command like so:

twilio api:core:messages:list --help

If you type a command, you might get an error if you haven’t provided all the required options. This is another situation where adding --help to the command can give you more information.

サンプル

List your phone numbers

twilio phone-numbers:list

SMSを送信

twilio api:core:messages:create \
  --from "+15017122661" \
  --to "+15558675310" \
  --body "I love you 3000"

More examples

Please visit our examples page for a gallery of more examples.

次は?

Now that you’ve been introduced to twilio-cli, where should you go from here?

Explore plugins

twilio-cli can be extended via plugins. You can publish your own for the community, or make them private for your own (or your clients') business workflows. There are already a number of plugins available for you to extend your CLI.

General usage guide

More examples

We have a whole page full of examples of the various things you can do with twilio-cli.

Send us feedback

Finally, we’d love to hear from you. Any time you have feedback you’d like to send us, just run:

twilio feedback
ページを評価:

ヘルプが必要ですか?

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.

        
        
        

        フィードバックくださりありがとうございます!

        We are always striving to improve our documentation quality, and your feedback is valuable to us. Please select the reason(s) for your feedback or provide additional information about how we can improve:

        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!

        ステップ1

        Get link

        Get a free personal referral link here

        ステップ2:

        Give $10

        Your user signs up and upgrade using link

        ステップ3

        Get $10

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