Twilio REST API provides two forms of authentication, Basic auth using Auth Tokens or API keys. These credentials are available on your Account dashboard when you log in.

You need to sign up on Twilio to access your authentication credentials. You'll have to provide your email, password, and a verified phone number to set up an account.

Authenticate with Auth tokens

You will use your Twilio Account SID as the username and your Auth Token as the password for HTTP Basic authentication.

curl -G <https://api.twilio.com/2010-04-01/Accounts>  
     -u \<YOUR_ACCOUNT_SID>:\<YOUR_AUTH_TOKEN>

Warning:

🛑 DO NOT SHARE your Auth Token or API keys to protect your account.

Authenticate with API Keys

API Keys are the preferred way to authenticate with Twilio's REST APIs. With API Keys, you control which applications and/or people have access to your Twilio Account's API resources, and you can revoke access at your discretion.

If your Twilio application uses one of the client-side SDKs, you must use API Keys to create Access Tokens.

There are three types of API Keys: Main, Standard, and Restricted (Public Beta):

  • Main API Keys provide access to the Account Resource of the Account that created the API Key. If you need API access to the Account Resource of a Subaccount, you need to create a Main API Key within the Subaccount.
  • Standard API Keysgive you access to all of the functionality in Twilio's APIs, _the following API Resources:
  • Restricted API Keys (Public Beta) allow you to provide fine-grained access to specific Twilio API Resources.

Create an API key in the Twilio Console

To create API Keys in the Twilio Console by following the steps below.

  • Click on Account in the top right-hand corner.
  • Under Keys & credentials, click on API keys & tokens (or follow this link
    ).
  • On the API keys & tokens page, click on the Create API Key button.
  • On the Create new API key page, enter a Friendly name for the API Key.
  • Select the key type: Restricted, Standard, or Main.
  • Click the Create API Key button.
  • On the Copy secret key page, Copy the Secret and store it somewhere secure.
  • Click on the Got it! checkbox and click Done.

Apply the API Key as follows:

You need two credentials; the API Key SID and the API SECRET Key

curl -X GET "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json" \
-u $TWILIO_API_KEY:$TWILIO_API_SECRET