REST API: API Keys

API Keys represent credentials to access the Twilio API. They are used for two purposes:

API Keys can be provisioned and revoked through the REST API or the Account Console, providing a powerful and flexible primitive for managing access to the Twilio API. For instance, you might issue separate API Keys to different developers, or to different subsystems within your application. Since API Keys can be independently revoked, you have complete control of the lifecycle of your API credentials.

An example of using API keys to authenticate a REST API request is below.

Loading Code Samples...
Language
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const apiSecret = 'your_api_secret';
const client = require('twilio')(accountSid, apiSecret);

// Create a message for your account (send an outbound SMS)
client.messages.create({
    to: '+15558675309', // the destination phone number
    from: '+15017250604', // a Twilio number in your account
    body: 'Never gonna give you up.', // body of a text message
  })
  .then((messageData) => console.log(messageData.sid));
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

/// Instantiate a client using your API key and secret - but then, you'll need to
// manually specify your main account (or subaccount) SID when making a request
$accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$apiKey = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$apiSecret = 'your_api_secret';
$client = new Client($apiKey, $apiSecret, $accountSid);

// Send a message for the main account
$message = $client->messages->create(
    '+15558675309', // destination phone number
    array(
        'from' => '+15017250604', // twilio number in your account
        'body' => 'Never gonna give you up.'
    )
);

echo $message->sid;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
api_key = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
api_secret = 'your_api_secret'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(api_key, api_secret, account_sid)

@message = @client.messages.create(
  to: '+15558675309',
  from: '+15017250604',
  body: 'Hello World!'
)

puts @message.sid
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String API_KEY = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String API_SECRET = "your_api_secret";

  public static void main(String[] args) {
    Twilio.init(API_KEY, API_SECRET, ACCOUNT_SID);

    Message message = Message.creator(new PhoneNumber("+15558675309"),
        new PhoneNumber("+15017250604"), "Never gonna give you up.").create();

    System.out.println(message.getSid());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
api_key = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
api_secret = "your_api_secret"

client = Client(api_key, api_secret, account_sid)

message = client.messages.create("+15558675309",
                                 from_='+15017250604',  # twilio number
                                 body='Never gonna give you up.')

print(message.sid)
// Download the Node helper library from twilio.com/docs/node/install
// Instantiate a client using your API key and secret - but then, you'll need to
// manually specify your main account (or subaccount) SID when making a request
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var apiKey = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var apiSecret = 'your_api_secret';
var client = require('twilio')(apiKey, apiSecret);

// Create a reference to your Twilio account
var account = client.accounts(accountSid);

// Create a message for your account (send an outbound SMS)
account.messages.create({
  to: '+15558675309', // the destination phone number
  from: '+15017250604', // a Twilio number in your account
  body: 'Never gonna give you up.' // body of a text message
}, (err, messageData) => {
  // print SID of the message you just sent
  console.log(messageData.sid);
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('./twilio-php/Services/Twilio.php');

// Instantiate a client using your API key and secret - but then, you'll need to
// manually specify your main account (or subaccount) SID when making a request
$accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$apiKey = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$apiSecret = 'your_api_secret';
$client = new Services_Twilio($apiKey, $apiSecret);

// Get a reference to the main account
$account = $client->accounts->get($accountSid);

// Send a message for the main account
$message = $account->messages->create(
    array(
      'To' => '+15558675309', // destination phone number
      'From' => '+15017250604', // twilio number in your account
      'Body' => 'Never gonna give you up.'
    )
);

echo $message->sid;
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \
    --data-urlencode "Body=Never gonna give you up." \
    --data-urlencode "To=+15558675309" \
    --data-urlencode "From=+15017250604" \
    -u 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_api_secret'
Use an API Key Pair to Send A Message

API Key Instance Resource

Resource URI

https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Keys/{API KeySid}

Resource Properties

An API Key is represented by the following properties:

Property Description
Sid A 34 character string that uniquely identifies this API Key. You will use this as the basic-auth user when authenticating to the API.
FriendlyName A descriptive string for this resource, chosen by your application, up to 64 characters long.
Secret The secret your application uses to sign Access Tokens and to authenticate to the REST API (you will use this as the basic-auth password).
Note that for security reasons, this field is ONLY returned when the API Key is first created.
DateCreated The date-time this API Key was created, given as a UTC ISO 8601 Timestamp.
DateUpdated The date-time this API Key was most recently updated, given as a UTC ISO 8601 Timestamp.

HTTP GET

Returns a representation of the Key, including the properties above.

Note that for security reasons, the Secret field is ONLY returned when the API Key is first created.

Example

An example API Key. Note that the API Key's Secret field is redacted; Secret fields are only returned when the API Key is first created.

Loading Code Samples...
Language
SDK Version:
  • 4.x
  • 5.x
Response Format:
  • json
  • xml
SDK Version:
  • 6.x
  • 7.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
$ curl -G https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys/SK2a0747eba6abf96b7e3c3ff0b4530f6e \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.keys('SK2a0747eba6abf96b7e3c3ff0b4530f6e')
  .fetch()
  .then((key) => console.log(key.friendlyName));
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var key = KeyResource.Fetch("SK2a0747eba6abf96b7e3c3ff0b4530f6e");

        Console.WriteLine(key.FriendlyName);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
$key = $client
    ->keys("SK2a0747eba6abf96b7e3c3ff0b4530f6e")
    ->fetch();

echo $key->friendlyName;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

key = client.keys.get("SK2a0747eba6abf96b7e3c3ff0b4530f6e")
print(key.friendly_name)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@key = @client.api.keys('SK2a0747eba6abf96b7e3c3ff0b4530f6e').fetch

puts @key.friendly_name
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Key;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    // Get an object from its sid. If you do not have a sid,
    // check out the list resource examples on this page
    Key key = Key.fetcher("SK2a0747eba6abf96b7e3c3ff0b4530f6e").fetch();

    System.out.println(key.getFriendlyName());
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Key;

public class Example {

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Get an object from its sid. If you do not have a sid,
    // check out the list resource examples on this page
    Key key = client.getAccount().getKey("SK2a0747eba6abf96b7e3c3ff0b4530f6e");
    System.out.println(key.getFriendlyName());

  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

key = client.keys("SK2a0747eba6abf96b7e3c3ff0b4530f6e") \
            .fetch()

print(key.friendly_name)
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.keys("SK2a0747eba6abf96b7e3c3ff0b4530f6e").get(function(err, key) {
    console.log(key.friendlyName);
});
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var key = twilio.GetKey("SK2a0747eba6abf96b7e3c3ff0b4530f6e");

    Console.WriteLine(key.FriendlyName);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Services_Twilio($sid, $token);

// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
$key = $client->account->keys->get("SK2a0747eba6abf96b7e3c3ff0b4530f6e");
echo $key->friendly_name;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

# Get an object from its sid. If you do not have a sid,
# check out the list resource examples on this page
@key = @client.account.keys.get("SK2a0747eba6abf96b7e3c3ff0b4530f6e")
puts @key.friendly_name
$ curl -G https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys/SK2a0747eba6abf96b7e3c3ff0b4530f6e.json \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
  "date_updated": "2015-05-14T23:44:32Z",
  "date_created": "2015-05-14T23:44:32Z",
  "friendly_name": "Foobar",
  "sid": "SKdac2dad1695721987de823226f0a62a4"
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
    <Key>
        <Sid>SKdac2dad1695721987de823226f0a62a4</Sid>
        <FriendlyName>Foobar</FriendlyName>
        <DateCreated>2015-05-14T23:44:32Z</DateCreated>
        <DateUpdated>2015-05-14T23:44:32Z</DateUpdated>
    </Key>
</TwilioResponse>
Get API Key Details

HTTP POST

Attempts to update the fields of an API Key instance and returns the updated resource representation if successful. If successful, the response will be identical to that of the HTTP GET.

Optional Parameters

You may specify one or more of the following parameters to update this API Key's properties:

Parameter Description
FriendlyName A descriptive string for this resource, chosen by your application, up to 64 characters long.

HTTP PUT

Not supported.

HTTP DELETE

Delete an API Key. This revokes its authorization to authenticate to the REST API, and invalidates all Access Tokens generated using its secret.

If the delete is successful, Twilio will return an HTTP 204 response with no body.

Note that you may only delete Keys by authenticating with the account's "master key" credentials - AccountSid and AuthToken.

API Keys List Resource

Resource URI

https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Keys

HTTP GET

Returns a list of API Keys in this account, sorted by DateUpdated. This list includes paging information.

All API Keys are included.

Example

Retrieve all the API Keys in an account:

Loading Code Samples...
Language
SDK Version:
  • 6.x
  • 7.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.keys
  .each((key) => console.log(friendlyName));
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

// Loop over the list of apps and echo a property for each one
foreach ($client->keys->read() as $key) {
    echo $key->friendlyName;
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

# A list of app objects with the properties described above
keys = client.keys.list()
for key in keys:
    print(key.friendly_name)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@client.keys.list.each do |key|
  puts key.friendly_name
end
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.base.ResourceSet;
import com.twilio.rest.api.v2010.account.Key;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    ResourceSet<Key> keys = Key.reader().read();

    // Loop over keys and print out a property for each one.
    for (Key key : keys) {
      System.out.println(key.getFriendlyName());
    }
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Key;
import com.twilio.sdk.resource.list.KeyList;

public class Example {

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    KeyList keys = client.getAccount().getKeys();

    // Loop over keys and print out a property for each one.
    for (Key key : keys) {
      System.out.println(key.getFriendlyName());
    }

  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

# A list of app objects with the properties described above
keys = client.keys.list()
for key in keys:
    print(key.friendly_name)
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.keys.list(function(err, data) {
    data.keys.forEach(function(key) {
        console.log(key.friendlyName);
    });
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Services_Twilio($sid, $token);

// Loop over the list of apps and echo a property for each one
foreach ($client->account->keys as $key) {
    echo $key->friendly_name;
}
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token


# Loop over apps and print out a property for each one
@client.account.keys.list.each do |key|
  puts key.friendly_name
end
$ curl -G https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys.json \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
	"page": 0,
	"page_size": 50,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Keys.json",
	"first_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Keys.json?Page=0&PageSize=50",
	"previous_page_uri": null,
	"next_page_uri": null,
	"keys": [
            {
                "date_updated": "2015-05-14T23:44:32Z",
                "date_created": "2015-05-14T23:44:32Z",
                "friendly_name": null,
                "sid": "SKdac2dad1695721987de823226f0a62a4"
            },
            ...
	]
}
<TwilioResponse>
	<Keys page="0" pagesize="50" uri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys" firstpageuri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys?Page=0&PageSize=50" previouspageuri="" nextpageuri="">
            <Key>
                <Sid>SKdac2dad1695721987de823226f0a62a4</Sid>
                <FriendlyName>Foobar</FriendlyName>
                <DateCreated>2015-05-14T23:44:32Z</DateCreated>
                <DateUpdated>2015-05-14T23:44:32Z</DateUpdated>
            </Key>
	</Keys>
</TwilioResponse>
Get All API Keys

HTTP POST

Creates a new API Key.

Note that you may only create new Keys by authenticating with the account's "master key" credentials - AccountSid and AuthToken.

Optional Parameters

Your request may include the following parameters:

Parameter Description
FriendlyName A descriptive string for this resource, chosen by your application, up to 64 characters long.

If successful, Twilio will respond with a representation of the new API Key. This representation will be exactly the same as that returned by issuing a GET to the API Key's instance resource, except that the Secret field will be included.

For security reasons, the API Key's Secret is only returned here, when the API Key is first created. Your application should store the API Key's Sid and Secret in a secure location to authenticate to the API and generate Access Tokens in the future.
Example

Create an API Key with the FriendlyName "User Jenny".

Loading Code Samples...
Language
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.api.account.newKeys.create({
    friendlyName: 'User Jenny',
  })
  .then((key) => {
    process.stdout.write(key.sid);
    process.stdout.write(key.secret);
  });
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var key = NewKeyResource.Create(friendlyName: "User Jenny");

        Console.WriteLine(key.Sid);
        Console.WriteLine(key.Secret);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$key = $client->newKeys->create(
    array('friendlyName' => 'User Jenny')
);

echo $key->sid;
echo $key->secret;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

key = client.keys.create(friendly_name="User Jenny")
print(key.sid)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@key = @client.new_keys.create(friendly_name: 'User Jenny')

puts @key.sid
puts @key.secret
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.NewKey;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    NewKey key = NewKey.creator().setFriendlyName("User Jenny").create();

    System.out.println(key.getSid());
    System.out.println(key.getSecret());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

key = client.new_keys \
            .create(friendly_name="User Jenny")

print(key.sid)
print(key.secret)
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.keys.create({
    friendlyName: "User Jenny",
}, function(err, key) {
    process.stdout.write(key.sid);
    process.stdout.write(key.secret);
});
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var key = twilio.AddKey("User Jenny");

    Console.WriteLine(key.Sid);
    Console.WriteLine(key.Secret);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Services_Twilio($sid, $token);

$key = $client->account->keys->create(array("FriendlyName" => "User Jenny"));
echo $key->sid;
echo $key->secret;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

key = @client.account.keys.create(friendly_name: "User Jenny")
puts key.sid
puts key.secret
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys.json \
    -d "FriendlyName=User+Jenny" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
    "secret": "RdXY0fRhkrP1scKYpv2SOHV2GrqHGjPw",
    "date_updated": "2015-05-14T23:44:32Z",
    "date_created": "2015-05-14T23:44:32Z",
    "friendly_name": "User Jenny",
    "sid": "SKdac2dad1695721987de823226f0a62a4"
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
    <Key>
        <Secret>rD7Y0frhkrPOzcKypv2SOHV8GrXHGJPw</Secret>
        <Sid>SKdac2dad1695721987de823226f0a62a4</Sid>
        <FriendlyName>User Jenny</FriendlyName>
        <DateCreated>2015-05-14T23:44:32Z</DateCreated>
        <DateUpdated>2015-05-14T23:44:32Z</DateUpdated>
    </Key>
</TwilioResponse>
Create an API Key

HTTP PUT

Not supported.

HTTP DELETE

Not supported.

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 browsing the Twilio tag on Stack Overflow.

1 / 1
Loading Code Samples...
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const apiSecret = 'your_api_secret';
const client = require('twilio')(accountSid, apiSecret);

// Create a message for your account (send an outbound SMS)
client.messages.create({
    to: '+15558675309', // the destination phone number
    from: '+15017250604', // a Twilio number in your account
    body: 'Never gonna give you up.', // body of a text message
  })
  .then((messageData) => console.log(messageData.sid));
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

/// Instantiate a client using your API key and secret - but then, you'll need to
// manually specify your main account (or subaccount) SID when making a request
$accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$apiKey = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$apiSecret = 'your_api_secret';
$client = new Client($apiKey, $apiSecret, $accountSid);

// Send a message for the main account
$message = $client->messages->create(
    '+15558675309', // destination phone number
    array(
        'from' => '+15017250604', // twilio number in your account
        'body' => 'Never gonna give you up.'
    )
);

echo $message->sid;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
api_key = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
api_secret = 'your_api_secret'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(api_key, api_secret, account_sid)

@message = @client.messages.create(
  to: '+15558675309',
  from: '+15017250604',
  body: 'Hello World!'
)

puts @message.sid
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String API_KEY = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String API_SECRET = "your_api_secret";

  public static void main(String[] args) {
    Twilio.init(API_KEY, API_SECRET, ACCOUNT_SID);

    Message message = Message.creator(new PhoneNumber("+15558675309"),
        new PhoneNumber("+15017250604"), "Never gonna give you up.").create();

    System.out.println(message.getSid());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
api_key = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
api_secret = "your_api_secret"

client = Client(api_key, api_secret, account_sid)

message = client.messages.create("+15558675309",
                                 from_='+15017250604',  # twilio number
                                 body='Never gonna give you up.')

print(message.sid)
// Download the Node helper library from twilio.com/docs/node/install
// Instantiate a client using your API key and secret - but then, you'll need to
// manually specify your main account (or subaccount) SID when making a request
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var apiKey = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var apiSecret = 'your_api_secret';
var client = require('twilio')(apiKey, apiSecret);

// Create a reference to your Twilio account
var account = client.accounts(accountSid);

// Create a message for your account (send an outbound SMS)
account.messages.create({
  to: '+15558675309', // the destination phone number
  from: '+15017250604', // a Twilio number in your account
  body: 'Never gonna give you up.' // body of a text message
}, (err, messageData) => {
  // print SID of the message you just sent
  console.log(messageData.sid);
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('./twilio-php/Services/Twilio.php');

// Instantiate a client using your API key and secret - but then, you'll need to
// manually specify your main account (or subaccount) SID when making a request
$accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$apiKey = 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$apiSecret = 'your_api_secret';
$client = new Services_Twilio($apiKey, $apiSecret);

// Get a reference to the main account
$account = $client->accounts->get($accountSid);

// Send a message for the main account
$message = $account->messages->create(
    array(
      'To' => '+15558675309', // destination phone number
      'From' => '+15017250604', // twilio number in your account
      'Body' => 'Never gonna give you up.'
    )
);

echo $message->sid;
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json \
    --data-urlencode "Body=Never gonna give you up." \
    --data-urlencode "To=+15558675309" \
    --data-urlencode "From=+15017250604" \
    -u 'SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_api_secret'
SDK Version:
  • 4.x
  • 5.x
Response Format:
  • json
  • xml
SDK Version:
  • 6.x
  • 7.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
$ curl -G https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys/SK2a0747eba6abf96b7e3c3ff0b4530f6e \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.keys('SK2a0747eba6abf96b7e3c3ff0b4530f6e')
  .fetch()
  .then((key) => console.log(key.friendlyName));
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var key = KeyResource.Fetch("SK2a0747eba6abf96b7e3c3ff0b4530f6e");

        Console.WriteLine(key.FriendlyName);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
$key = $client
    ->keys("SK2a0747eba6abf96b7e3c3ff0b4530f6e")
    ->fetch();

echo $key->friendlyName;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

key = client.keys.get("SK2a0747eba6abf96b7e3c3ff0b4530f6e")
print(key.friendly_name)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@key = @client.api.keys('SK2a0747eba6abf96b7e3c3ff0b4530f6e').fetch

puts @key.friendly_name
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Key;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    // Get an object from its sid. If you do not have a sid,
    // check out the list resource examples on this page
    Key key = Key.fetcher("SK2a0747eba6abf96b7e3c3ff0b4530f6e").fetch();

    System.out.println(key.getFriendlyName());
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Key;

public class Example {

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    // Get an object from its sid. If you do not have a sid,
    // check out the list resource examples on this page
    Key key = client.getAccount().getKey("SK2a0747eba6abf96b7e3c3ff0b4530f6e");
    System.out.println(key.getFriendlyName());

  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

key = client.keys("SK2a0747eba6abf96b7e3c3ff0b4530f6e") \
            .fetch()

print(key.friendly_name)
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.keys("SK2a0747eba6abf96b7e3c3ff0b4530f6e").get(function(err, key) {
    console.log(key.friendlyName);
});
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var key = twilio.GetKey("SK2a0747eba6abf96b7e3c3ff0b4530f6e");

    Console.WriteLine(key.FriendlyName);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Services_Twilio($sid, $token);

// Get an object from its sid. If you do not have a sid,
// check out the list resource examples on this page
$key = $client->account->keys->get("SK2a0747eba6abf96b7e3c3ff0b4530f6e");
echo $key->friendly_name;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

# Get an object from its sid. If you do not have a sid,
# check out the list resource examples on this page
@key = @client.account.keys.get("SK2a0747eba6abf96b7e3c3ff0b4530f6e")
puts @key.friendly_name
$ curl -G https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys/SK2a0747eba6abf96b7e3c3ff0b4530f6e.json \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
  "date_updated": "2015-05-14T23:44:32Z",
  "date_created": "2015-05-14T23:44:32Z",
  "friendly_name": "Foobar",
  "sid": "SKdac2dad1695721987de823226f0a62a4"
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
    <Key>
        <Sid>SKdac2dad1695721987de823226f0a62a4</Sid>
        <FriendlyName>Foobar</FriendlyName>
        <DateCreated>2015-05-14T23:44:32Z</DateCreated>
        <DateUpdated>2015-05-14T23:44:32Z</DateUpdated>
    </Key>
</TwilioResponse>
SDK Version:
  • 6.x
  • 7.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.keys
  .each((key) => console.log(friendlyName));
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

// Loop over the list of apps and echo a property for each one
foreach ($client->keys->read() as $key) {
    echo $key->friendlyName;
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

# A list of app objects with the properties described above
keys = client.keys.list()
for key in keys:
    print(key.friendly_name)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@client.keys.list.each do |key|
  puts key.friendly_name
end
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.base.ResourceSet;
import com.twilio.rest.api.v2010.account.Key;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    ResourceSet<Key> keys = Key.reader().read();

    // Loop over keys and print out a property for each one.
    for (Key key : keys) {
      System.out.println(key.getFriendlyName());
    }
  }
}
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Key;
import com.twilio.sdk.resource.list.KeyList;

public class Example {

  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) throws TwilioRestException {
    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    KeyList keys = client.getAccount().getKeys();

    // Loop over keys and print out a property for each one.
    for (Key key : keys) {
      System.out.println(key.getFriendlyName());
    }

  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

# A list of app objects with the properties described above
keys = client.keys.list()
for key in keys:
    print(key.friendly_name)
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.keys.list(function(err, data) {
    data.keys.forEach(function(key) {
        console.log(key.friendlyName);
    });
});
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Services_Twilio($sid, $token);

// Loop over the list of apps and echo a property for each one
foreach ($client->account->keys as $key) {
    echo $key->friendly_name;
}
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token


# Loop over apps and print out a property for each one
@client.account.keys.list.each do |key|
  puts key.friendly_name
end
$ curl -G https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys.json \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
	"page": 0,
	"page_size": 50,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Keys.json",
	"first_page_uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Keys.json?Page=0&PageSize=50",
	"previous_page_uri": null,
	"next_page_uri": null,
	"keys": [
            {
                "date_updated": "2015-05-14T23:44:32Z",
                "date_created": "2015-05-14T23:44:32Z",
                "friendly_name": null,
                "sid": "SKdac2dad1695721987de823226f0a62a4"
            },
            ...
	]
}
<TwilioResponse>
	<Keys page="0" pagesize="50" uri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys" firstpageuri="/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys?Page=0&PageSize=50" previouspageuri="" nextpageuri="">
            <Key>
                <Sid>SKdac2dad1695721987de823226f0a62a4</Sid>
                <FriendlyName>Foobar</FriendlyName>
                <DateCreated>2015-05-14T23:44:32Z</DateCreated>
                <DateUpdated>2015-05-14T23:44:32Z</DateUpdated>
            </Key>
	</Keys>
</TwilioResponse>
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 2.x
  • 3.x
SDK Version:
  • 4.x
  • 5.x
SDK Version:
  • 5.x
  • 6.x
SDK Version:
  • 4.x
  • 5.x
Format:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.api.account.newKeys.create({
    friendlyName: 'User Jenny',
  })
  .then((key) => {
    process.stdout.write(key.sid);
    process.stdout.write(key.secret);
  });
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var key = NewKeyResource.Create(friendlyName: "User Jenny");

        Console.WriteLine(key.Sid);
        Console.WriteLine(key.Secret);
    }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Client($sid, $token);

$key = $client->newKeys->create(
    array('friendlyName' => 'User Jenny')
);

echo $key->sid;
echo $key->secret;
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token  = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)

key = client.keys.create(friendly_name="User Jenny")
print(key.sid)
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'twilio-ruby'

# Get your Account SID and Auth Token from twilio.com/console
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'

# Initialize Twilio Client
@client = Twilio::REST::Client.new(account_sid, auth_token)

@key = @client.new_keys.create(friendly_name: 'User Jenny')

puts @key.sid
puts @key.secret
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.NewKey;

public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "your_auth_token";

  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    NewKey key = NewKey.creator().setFriendlyName("User Jenny").create();

    System.out.println(key.getSid());
    System.out.println(key.getSecret());
  }
}
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

key = client.new_keys \
            .create(friendly_name="User Jenny")

print(key.sid)
print(key.secret)
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
var accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var authToken = "your_auth_token";
var client = require('twilio')(accountSid, authToken);

client.keys.create({
    friendlyName: "User Jenny",
}, function(err, key) {
    process.stdout.write(key.sid);
    process.stdout.write(key.secret);
});
// Download the twilio-csharp library from twilio.com/docs/csharp/install
using System;
using Twilio;
class Example
{
  static void Main(string[] args)
  {
    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
    string AuthToken = "your_auth_token";
    var twilio = new TwilioRestClient(AccountSid, AuthToken);

    var key = twilio.AddKey("User Jenny");

    Console.WriteLine(key.Sid);
    Console.WriteLine(key.Secret);
  }
}
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Services_Twilio($sid, $token);

$key = $client->account->keys->create(array("FriendlyName" => "User Jenny"));
echo $key->sid;
echo $key->secret;
# Get twilio-ruby from twilio.com/docs/ruby/install
require 'rubygems'          # This line not needed for ruby > 1.8
require 'twilio-ruby'

# Get your Account Sid and Auth Token from twilio.com/user/account
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
@client = Twilio::REST::Client.new account_sid, auth_token

key = @client.account.keys.create(friendly_name: "User Jenny")
puts key.sid
puts key.secret
$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Keys.json \
    -d "FriendlyName=User+Jenny" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
    "secret": "RdXY0fRhkrP1scKYpv2SOHV2GrqHGjPw",
    "date_updated": "2015-05-14T23:44:32Z",
    "date_created": "2015-05-14T23:44:32Z",
    "friendly_name": "User Jenny",
    "sid": "SKdac2dad1695721987de823226f0a62a4"
}
<?xml version='1.0' encoding='UTF-8'?>
<TwilioResponse>
    <Key>
        <Secret>rD7Y0frhkrPOzcKypv2SOHV8GrXHGJPw</Secret>
        <Sid>SKdac2dad1695721987de823226f0a62a4</Sid>
        <FriendlyName>User Jenny</FriendlyName>
        <DateCreated>2015-05-14T23:44:32Z</DateCreated>
        <DateUpdated>2015-05-14T23:44:32Z</DateUpdated>
    </Key>
</TwilioResponse>