通話を発信する

Twilio REST APIを使用して、電話、SIPエンドポイント、およびTwilio Client接続に対して通話を発信できます。

コードサンプルを完了するステップバイステップの手順については、使い慣れたプログラミング言語向けの通話の発信方法を参照してください。

REST API で発信する通話は、1 秒 1 通話の発信制限がありますので、注意してください。 通話をキューに入れる場合は無制限に入れることができますが、通話がキューを外れる際は 1 秒 1 通話となります。

Twilioには公開ベータ中の留守番電話検出機能が用意されています。早期アクセスをご希望の場合は、こちらのドキュメントをご参照ください。

CallsへのHTTP POSTリクエスト

通話を発信するには、アカウントのCallリストリソースURIに対してHTTP POSTリクエストを送信します:

/2010-04-01/Accounts/{AccountSid}/Calls

POSTパラメーター

必須パラメーター

下記のパラメーターをPOSTしなければなりません

パラメーター 説明
To 宛先の電話番号、SIPアドレスまたはクライアント識別子です。
From 発信者IDとして使用する電話番号またはClient識別子です。

電話番号を使用する場合は、アカウントのTwilio番号または検証済みの発信者IDであることが必要です。 なお、日本国内への発信には検証済み電話番号は使用できません。

Toパラメーターが電話番号の場合は、Fromもまた電話番号でなければなりません。

電話番号は+16175551212のような、「+」記号と国番号の組み合わせ(E.164形式)で書かれている必要があります。

トライアルアカウントから通話を発信する場合は、「To」番号はTwilioで検証済みであることが必要です。 Console内の検証済み発信者IDに電話番号追加することで、これを検証が行えます。

SIPのアドレスは sip:name@example.com という形式である必要があります。 たとえば、Example株式会社のAliceのSIPアドレスにダイヤルするには、Toパラメーターは sip:alice@example.com のようになります。

Client識別子はclient URIスキームで開始する必要があります。 たとえば、「joey」という名前のClientに発信するには、Toパラメーターは client:joey のようになります。

次のパラメーターのいずれか 1 つ を 必ず POST してください。

パラメーター 説明
url 通話を接続する時に使う完全修飾 URL です。 着信通話を処理するために、電話番号に URL をセットするのと同じです。 詳細は、後述の URL パラメーター のセクションを参照してください。
ApplicationSid この通話を処理するために Twilio が使用するアプリケーションの、34 文字の sid です。 このパラメーターが設定さている場合、Twilio は渡されたすべての URL を無視して、アプリケーションの設定を使用します。 詳細は、後述の ApplicationSid パラメーター のセクションを参照してください。

Url パラメーター

REST APIで通話を開始すると、Twilioは通話の処理方法の記述されたTwiMLを取得するため、「url」POSTパラメーターで指定されたURLに対して同期HTTPリクエストを送信します。 このリクエストはTwilio番号への通話の着信時にTwilioが送信するリクエストと同じものです。 URLには有効なホスト名が含まれていなければなりません(アンダースコアは使用できません)。

ApplicationSid パラメーター

Twilio内では、アプリケーションとは音声通話とSMSを処理するための一連のURLとその他の構成データです。 アカウントポータルのAppsセクションでアプリケーションを構成できます。 アプリケーションには音声通話の処理に必要な情報がすべて含まれているため、通話の発信処理にアプリケーションを使用するのは理にかなっています。

ApplicationSidパラメーターをPOSTすると、TwilioはそのアプリケーションからのすべてのURLとその他の構成情報を使用して発信通話を処理します。POST中のUrl、Method、FallbackUrl、FallbackMethod、StatusCallback、StatusCallbackMethodパラメーターは無視します。

発信通話が接続されると、Twilioはアプリケーションで設定された「VoiceUrl」に対してリクエストが送信されます。 このリクエストはTwilioが「Url」パラメーターに対して本来送信を行う、上記で説明されているようなリクエストと同じものです。

通話の終了後は、Twilioはアプリケーションに設定されたStatusCallback URLに非同期のHTTPリクエストを送信します。 このリクエストは「StatusCallback」パラメーターに本来送信を行うリクエストと同じものです。

オプションパラメーター

下記のパラメーターをPOST可能です:

パラメーター 説明
method 上述の Url パラメーターの値へリクエストを発行する際に、Twilio が使用する HTTP のメソッドです。 初期値は POST です。 ApplicationSid パラメーターが設定されている場合、このパラメーターは無視されます。
FallbackUrl 上述の Url の TwiML のリクエストまたは実行時にエラーが発生した場合、Twilio がリクエストを送信する URL です。 ApplicationSid パラメーターが設定されている場合、このパラメーターは無視されます。
FallbackMethod FallbackUrl へリクエストを送信する際に、Twilio が使用する HTTP のメソッドです。 必ず GET または POST のいずれかとします。 初期値は POST です。 ApplicationSid パラメーターが設定されている場合、このパラメーターは無視されます。
StatusCallback Twilioは非同期のwebhookリクエスト URLを特定されるStatusCallbackEvent パラメータで特定される全ての通話イベントにリクエストします。イベントが無い場合、Twilioはcompletedをデフォルトで送ります。ApplicationSidパラメーターが存在する場合、このパラメーターは無視されます。URLは正しい形式のホスト名を含む必要があります。(ホスト名にはアンダーバーは使えません)
statusCallbackMethod 上述の URL へリクエストを送信する際に、Twilio が使用する HTTP のメソッドです。 初期値は POST です。 ApplicationSid パラメーターが設定されている場合、このパラメーターは無視されます。
StatusCallbackEvent TwilioがWebhookに対して送信する通話の進行イベントです。 利用可能な値はinitiatedringinganswered、およびcompletedです。 複数のイベントを受信したい場合は、複数のStatusCallbackEventの値をPOSTリクエスト内の個別のパラメーターとして渡します。 コードサンプルについては、通話の進行状況をモニターするを参照してください。 イベントが指定されない場合、既定ではcompletedとなります。 ApplicationSidが存在する場合、このパラメーターは無視されます。
SendDigits 番号(最大で 32 個の数字)に接続した後にダイヤルするキーの文字列です。この文字列で有効な数字は、任意の数字(0 ~ 9)、「#」、「*」および「w」(0.5 秒のポーズを挿入)です。たとえば、会社の電話番号に接続して 1 秒間のポーズを入れ、内線番号 1234 をダイヤルし、 # キーを押す場合は、SendDigits=ww1234# と指定します。 文字「#」は URL の中で特別な意味を持つため、この文字列は URL エンコードしてください。SendDigits および MachineDetection の両パラメーターが指定されている場合は、MachineDetection は無視されます。
MachineDetection 人間、留守番電話、またはFaxのいずれかが電話を取ったかを検出します。 Twilioが着信側を識別できたらすぐにAnsweredByを返させたい場合はEnableを使用します。 留守番電話にメッセージを残したい場合は、DetectMessageEndを指定します。 SendDigitsおよびMachineDetectionパラメーターの両方が指定された場合、MachineDetectionは無視されます。 こちらで詳細ドキュメントをご確認ください
MachineDetectionTimeout タイムアウト前にTwilioが留守番電話検出の実行を試み、AnsweredByunknownにVoiceリクエストの送信を試みるまでの秒数です。既定は30秒です。
Timeout 相手から応答がないと判断するまで、呼び出し音を鳴らし続ける時間を、整数値(秒)で指定します。規定は60秒で、最大値は600秒です。通話フローによっては、Twilioは指定されたタイムアウトに5秒のバッファーを追加するため、たとえば10秒のタイムアウトを指定した場合、実際のタイムアウトは15秒近くなることも考えられます。これを15のような小さい値に設定することで、自動応答システムや留守番電話が通話を取る前に切断できます。
Record Set this parameter to 'true' to record the entirety of a phone call.  既定値は 'false' です。
RecordingChannels mono または dual

最終的なレコーディングのチャンネル数をこのパラメーターで設定します。 既定では 'mono' です。

モノ・チャンネルでは、通話の両方のレグが単一の録音ファイル内の単一のチャンネルにミックスダウンされます。 デュアル・チャンネルでは、両方のレグが単一の録音ファイル内の別々のチャンネルを使用します。 デュアル・チャンネルでは、親コールは常に第1チャンネルに、そして子コールは常に第2チャンネルに割り当てられます。
RecordingStatusCallback 録音がアクセス可能になったときにTwilioがWebhookを送信する先のURLです。
RecordingStatusCallbackMethod 上述の URL へリクエストを送信する際に、Twilio が使用する HTTP のメソッドです。 初期値は POST です。
RecordingStatusCallbackEvent RecordingStatusCallbackで指定されたURLにTwilioがWebhookを送信する録音のステータス変更を指定します。 利用可能な値はin-progresscompleted、およびfailedです。 複数の値を指定するには、空白文字で区切ります。 既定値はcompletedfailedです。 いずれかの値が指定されると、既定値は適用されなくなります。

 リクエストパラメーター

Twilioが開発者のアプリケーションへのリクエストに渡すパラメーターには、Twilio番号に通話が着信した際にTwiMLを取得するための同期リクエストにてTwilioが渡す全パラメーターが含まれます。 これらのパラメーターとその各説明については、TwiML Voice: Twilioのリクエストドキュメントを参照してください。 リクエスト内でMachineDetectionパラメーターを使用している場合には追加のパラメーターがあります。

パラメーター 説明
AnsweredBy 留守番電話検出の結果です。 Enableが指定された場合、結果はmachine_start, human、fax、unknownのいずれかです。 DetectMessageEndが指定された場合は、結果はmachine_end_beep、machine_end_silence、machine_end_other、human、fax、unknownのいずれかです。

StatusCallbackパラメーター

StatusCallbackEvent パラメーターで指定されるすべての通話の進行イベントについて、POSTリクエストにStatusCallbackを指定している場合、Twilioはそこに非同期のWebhookリクエストを送信します。

リクエストパラメーター

TwilioがStatusCallback URLへの非同期リクエストで開発者のアプリケーションに渡すパラメーターには、Twilio番号に通話が着信した際にTwiMLを取得するための同期リクエストにてTwilioが渡す全パラメーターが含まれます。 パラメーターの全一覧とその各説明については、TwiML Voiceリクエストドキュメントに記載されています。 URLには有効なホスト名を指定しなければなりません(アンダースコアは使用できません)。

コールプログレスイベントが発動された時、コールバックリクエストは、この他にも次のパラメーターを渡します。

パラメーター 説明
CallStatus このコールのステータス詳細取りうる値は queued(キューに入った), initiated(処理が開始された), ringing(呼び出し中), in-progress(通話中), busy(話し中), failed(失敗), no-answer(電話に出ず) です。詳細はコールのステータス セクションをご覧ください
CallDuration 通話の秒数completedのイベントにのみ現れます。
SipResponseCode 通話失敗の結果によるSIPコードです。 例えば、到達不可能な番号には404が、通話が接続する前にタイムアウト値に達した場合は487が返る、などです。 CallStatusが failed または no-answer のときのみ、completed イベント中に現れます。
RecordingUrl 音声通話の録音済みオーディオのURLです。 このパラメーターは REST APIリクエストに Record=true が設定されている場合にのみ含まれ、他の方法で開始された録音は含まれません。 RecordingUrlcompleted イベント内にのみ存在します。 録音ファイルは ステータス・コールバック送信時にはまだアクセスできない場合があります。 録音がアクセス可能になった際に確実に通知を受け取るには、RecordingStatusCallbackを使用してください。
RecordingSid この通話から発生した録音の一意なIDRecordingSidcompletedのイベントでのみ発生します。
RecordingDuration 録音されたオーディオの長さ (秒) です。 RecordingDurationcompleted イベント内にのみ存在します。 無音部分を削除した後の正確な録音の長さの確定値を取得するには、RecordingStatusCallbackを使用してください。
Timestamp このイベントが生成された日付の UTC 表記です。RFC 2822フォーマットを使用します。
CallbackSource webhookのソースを記述する文字webhookがなぜ発生したか曖昧さの排除に役立ちます。Status Callback では、値は常にcall-progress-eventsです。
SequenceNumber イベントが発動する順番は、0から始まります。イベントが順々に発動すると、分離されたHTTPリクエストを生成し、同じ順番の到着は保証されません。

 

StatusCallbackEventパラメーター

Callsリソースに対するPOSTリクエストを送信する際、発信のCallインスタンスが作成され、通話はqueued (キューイング済み) ステータスとなります。 通話がinitiated(開始済み)ステータスに移行され、ダイヤルが開始すると、initiatedイベントが発動されます。 ringing (呼び出し中) イベントは着信側の電話機の呼び鈴が鳴り始めると発動されます。 着信側が電話に出ると、answered (応答済み) イベントが発動され、通話はin-progress (進行中) ステータスに移行します。 通話が終了すると、最終的にcompleted (完了) イベントが発動されます。

StatusCallbackEventパラメーターを使用すると、Twilioがどのイベントに対してWebhookを送信するかを指定できます。 複数のStatusCallbackEventの値を指定することで、複数のイベントを指定できます(こちらの例を参照してください)。 StatusCallbackが指定され、かつStatusCallbackEventが指定されなかった場合、既定でcompletedイベントが送信されます。

下記の返却されうるコールイベントのタイムラインです。異なるコールステータスがアウトパウンドコールで発生します。

イベントのタイムラインと発信通話の通話ステータス

イベント 説明
queued queued イベントは、Twilio が通話を作成して、その通話を通話キューに追加したときに発動します。
initiated initiated イベントは、Twilio がキューから通話を削除して、その通話のダイヤルを開始したときに発動します。
ringing 電話が鳴り始めると、ringingイベントが発動します。
answered 通話を開始(受話)するとansweredイベントが発動します。
completed completedイベントは端末の状態に関係なく(busycanceledcompletedfailedno-answer)コールが終了した時に発動します。 StatusCallbackEventが指定されない場合、completedがデフォルトで発動されます。

RecordingStatusCallbackパラメーター

「recordingStatusCallback」属性は、絶対 URL を引数に取ります。

通話に対する録音が要求され、'RecordingStatusCallback' URLが与えられた場合、Twilioはレコーディングがアクセス可能になった時点でGETまたはPOSTリクエストを指定されたURLに送信します。

リクエストパラメーター

Twilio は、リクエストと以下のパラメーターを「recordingStatusCallback」URL へ転送します。

パラメーター 説明
AccountSid この録音の属するアカウントの一意な識別子です。
CallSid 録音に関連づけられた通話の一意な識別子です。 これは常に、2つの呼により構成される通話の親コールを参照します。
RecordingSid この録音のユニークな識別子です。
RecordingUrl 録音された音声の URL。
RecordingStatus The status of the recording. Possible values are: in-progress, completed, failed.
RecordingDuration この録音の長さ (秒) です。
RecordingChannels 最終的な録音ファイルのチャンネル数を示す整数です。 取りうる値は 1 および 2 です。
RecordingSource 録音の作成された通話の種類です。 REST APIでRecord=trueが設定され開始された録音の場合はOutboundAPIが返されます。

RecordingStatusCallbackMethod

この属性は、「recordingStatusCallback」のリクエスト送信に使う HTTP メソッドを指定します。デフォルトは「POST」です。

RecordingStatusCallbackEvent

この属性を使用すると、どの録音ステータス変更でRecordingStatusCallbackで指定されたURLへのWebhookを生成すべきか指定できます。 利用可能な値はin-progresscompleted、およびfailedです。 複数の値を指定する際は、空白文字で区切ります。 既定値はcompletedfailedです。 いずれかの値が指定されると、既定値は適用されなくなります。 (録音を一時停止、再開、停止するには、Call Recording Control APIRecordingStatusCallbackEventを使用します。)

既定でのステータス変更イベントは以下の通りです:

パラメーター 説明
in-progress 録音が開始されました
completed 録音が完了しアクセス可能です
failed 録音は失敗したため利用できません

サンプル

通話の発信

Twilio電話番号から通話を発信します。 Twilioはhttp://demo.twilio.com/docs/voice.xmlに対して通話を処理するTwiMLを取得しに行きます。

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls.create(
  {
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    from: '+15017122661',
  },
  (err, call) => {
    process.stdout.write(call.sid);
  }
);
// 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.calls
  .create({
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    from: '+15017122661',
  })
  .then(call => process.stdout.write(call.sid));
// 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 options = new CallOptions();
    options.Url = "http://demo.twilio.com/docs/voice.xml";
    options.To = "+14155551212";
    options.From = "+15017122661";
    var call = twilio.InitiateOutboundCall(options);
    
    Console.WriteLine(call.Sid);
  }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->account->calls->create("+15017122661", "+14155551212", "http://demo.twilio.com/docs/voice.xml", array());
echo $call->sid;
# 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

call = @client.account.calls
              .create(url: 'http://demo.twilio.com/docs/voice.xml',
                      to: '+14155551212',
                      from: '+15017122661')
puts call.to
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

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 to = new PhoneNumber("+14155551212");
        var from = new PhoneNumber("+15017122661");
        var call = CallResource.Create(to,
                                       from,
                                       url: new Uri("http://demo.twilio.com/docs/voice.xml"));

        Console.WriteLine(call.Sid);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->calls->create(
    "+14155551212", "+14158675310",
    array("url" => "http://demo.twilio.com/docs/voice.xml")
);

echo $call->sid;
# 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)

call = client.calls.create(
    url="http://demo.twilio.com/docs/voice.xml",
    to="+14155551212",
    from_="+15017122661"
)
print(call.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)

@call = @client.calls.create(
  url: 'http://demo.twilio.com/docs/voice.xml',
  to: '+14155551212',
  from: '+15017122661'
)

puts @call.sid
// 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.factory.CallFactory;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

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);

    // Build a filter for the CallList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
    params.add(new BasicNameValuePair("To", "+14155551212"));
    params.add(new BasicNameValuePair("From", "+15017122661"));
    
    
    CallFactory callFactory = client.getAccount().getCallFactory();
    Call call = callFactory.create(params);
    System.out.println(call.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"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls.create(
    to="+14155551212",
    from_="+15017122661",
    url="http://demo.twilio.com/docs/voice.xml"
)

print(call.sid)
// Install the Java helper library from twilio.com/docs/java/install
import java.net.URI;
import java.net.URISyntaxException;

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;
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 AUTH_TOKEN = "your_auth_token";

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

    Call call = Call.creator(new PhoneNumber("+14155551212"), new PhoneNumber("+15017122661"),
        new URI("http://demo.twilio.com/docs/voice.xml")).create();

    System.out.println(call.getSid());
  }
}
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "From=+14158675310" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "From=+14158675310" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
	"sid": "CAa346467ca321c71dbd5e12f627deb854",
	"date_created": "Thu, 19 Aug 2010 00:12:15 +0000",
	"date_updated": "Thu, 19 Aug 2010 00:12:15 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "+14155551212",
	"formatted_to": "(415) 555-1212",
	"from": "+14158675310",
	"formatted_from": "(415) 867-5310",
	"phone_number_sid": "PNd6b0e1e84f7b117332aed2fd2e5bbcab",
	"status": "queued",
	"start_time": null,
	"end_time": null,
	"duration": null,
	"price": null,
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2010-04-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854.json",
	"subresource_uris": {
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAa346467ca321c71dbd5e12f627deb854</Sid>
		<DateCreated>Thu, 19 Aug 2010 00:25:48 +0000</DateCreated>
		<DateUpdated>Thu, 19 Aug 2010 00:25:48 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>+14155551212</To>
		<FormattedTo>(415) 555-1212</FormattedTo>
		<From>+14158675310</From>
		<FormattedFrom>(415) 867-5310</FormattedFrom>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>queued</Status>
		<StartTime/>
		<EndTime/>
		<Duration/>
		<Price/>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2010-04-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>
Twilio電話番号から通話を発信しましょう。 
通話の発信

Twilio電話番号から通話を発信しましょう。 

Twilio Clientエンドポイントに通話を発信する

tommyという名前のTwilio Clientに対して通話を発信します。 Twilioはhttp://demo.twilio.com/docs/voice.xmlに対して通話を処理するTwiMLを取得しに行きます。

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls.create(
  {
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: 'client:charlie',
    from: '+15017122661',
  },
  (err, call) => {
    process.stdout.write(call.sid);
  }
);
// 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.calls
  .create({
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: 'client:charlie',
    from: '+15017122661',
  })
  .then(call => process.stdout.write(call.sid));
// 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 options = new CallOptions();
    options.Url = "http://demo.twilio.com/docs/voice.xml";
    options.To = "client:charlie";
    options.From = "+15017122661";
    var call = twilio.InitiateOutboundCall(options);
    
    Console.WriteLine(call.Sid);
  }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->account->calls->create("+14158675310", "client:charlie", "http://demo.twilio.com/docs/voice.xml", array());
echo $call->sid;
# 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

call = @client.account.calls
              .create(url: 'http://demo.twilio.com/docs/voice.xml',
                      to: 'client:charlie',
                      from: '+15017122661')
puts call.start_time
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

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 to = new Client("client:charlie");
        var from = new PhoneNumber("+15017122661");
        var call = CallResource.Create(to,
                                       from,
                                       url: new Uri("http://demo.twilio.com/docs/voice.xml"));

        Console.WriteLine(call.Sid);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->calls->create(
    "client:charlie", "+14158675310",
    array("url" => "http://demo.twilio.com/docs/voice.xml")
);

echo $call->sid;
# 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)

call = client.calls.create(
    url="http://demo.twilio.com/docs/voice.xml",
    to="client:charlie",
    from_="+15017122661"
)
print(call.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)

@call = @client.calls.create(
  url: 'http://demo.twilio.com/docs/voice.xml',
  to: 'client:charlie',
  from: '+15017122661'
)

puts @call.start_time
// 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.factory.CallFactory;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

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);

    // Build a filter for the CallList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
    params.add(new BasicNameValuePair("To", "client:charlie"));
    params.add(new BasicNameValuePair("From", "+15017122661"));
    
    
    CallFactory callFactory = client.getAccount().getCallFactory();
    Call call = callFactory.create(params);
    System.out.println(call.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"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls.create(
    to="client:charlie",
    from_="+15017122661",
    url="http://demo.twilio.com/docs/voice.xml"
)

print(call.sid)
// Install the Java helper library from twilio.com/docs/java/install
import java.net.URI;
import java.net.URISyntaxException;

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;
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 AUTH_TOKEN = "your_auth_token";

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

    Call call = Call.creator(new PhoneNumber("client:charlie"), new PhoneNumber("+15017122661"),
        new URI("http://demo.twilio.com/docs/voice.xml")).create();

    System.out.println(call.getSid());
  }
}
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=client:charlie" \
    --data-urlencode "From=+15017122661" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=client:charlie" \
    --data-urlencode "From=+15017122661" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
	"sid": "CAa346467ca321c71dbd5e12f627deb854",
	"date_created": "Thu, 19 Aug 2010 00:12:15 +0000",
	"date_updated": "Thu, 19 Aug 2010 00:12:15 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "client:charlie",
	"formatted_to": "charlie",
	"from": "+14158675310",
	"formatted_from": "(415) 867-5310",
	"phone_number_sid": "PNd6b0e1e84f7b117332aed2fd2e5bbcab",
	"status": "queued",
	"start_time": null,
	"end_time": null,
	"duration": null,
	"price": null,
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2010-04-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854.json",
	"subresource_uris": {
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAa346467ca321c71dbd5e12f627deb854</Sid>
		<DateCreated>Thu, 19 Aug 2010 00:25:48 +0000</DateCreated>
		<DateUpdated>Thu, 19 Aug 2010 00:25:48 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>client:charlie</To>
		<FormattedTo>charlie</FormattedTo>
		<From>+14158675310</From>
		<FormattedFrom>(415) 867-5310</FormattedFrom>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>queued</Status>
		<StartTime/>
		<EndTime/>
		<Duration/>
		<Price/>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2010-04-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>
Twilio Clientに通話を発信する

通話を発信し、プッシュ信号を送信する

通話を発信し、接続後に内線番号1234#をダイヤルします。 TwilioはGETリクエストを送信し、 `http://demo.twilio.com/docs/voice.xml` に対して通話を処理するTwiMLを取得しに行きます。

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls.create(
  {
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    sendDigits: '1234#',
    from: '+18668675310',
    method: 'GET',
  },
  (err, call) => {
    process.stdout.write(call.sid);
  }
);
// 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.calls
  .create({
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    sendDigits: '1234#',
    from: '+18668675310',
    method: 'GET',
  })
  .then(call => process.stdout.write(call.sid));
// 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 options = new CallOptions();
    options.Url = "http://demo.twilio.com/docs/voice.xml";
    options.To = "+14155551212";
    options.SendDigits = "1234#";
    options.From = "+18668675310";
    options.Method = "GET";
    var call = twilio.InitiateOutboundCall(options);
    
    Console.WriteLine(call.Sid);
  }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->account->calls->create("+18668675310", "+14155551212", "http://demo.twilio.com/docs/voice.xml", array(
        "SendDigits" => "1234#",
    "Method" => "GET"
    ));
echo $call->sid;
# 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

call = @client.account.calls
              .create(url: 'http://demo.twilio.com/docs/voice.xml',
                      to: '+14155551212',
                      send_digits: '1234#',
                      from: '+18668675310',
                      method: 'GET')
puts call.start_time
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using Twilio.Http;

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 to = new PhoneNumber("+14155551212");
        var from = new PhoneNumber("+18668675310");
        var call = CallResource.Create(
            to,
            from,
            url: new Uri("http://demo.twilio.com/docs/voice.xml"),
            sendDigits: "1234#",
            method: new HttpMethod("GET"));

        Console.WriteLine(call.Sid);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->calls->create(
    "+14155551212", "+18668675310",
    array(
        "url" => "http://demo.twilio.com/docs/voice.xml",
        "sendDigits" => "1234#",
        "method" => "GET"
    )
);

echo $call->sid;
# 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)

call = client.calls.create(
    url="http://demo.twilio.com/docs/voice.xml",
    to="+14155551212",
    send_digits="1234#",
    from_="+18668675310",
    method="GET"
)
print(call.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)

call = @client.calls.create(
  url: 'http://demo.twilio.com/docs/voice.xml',
  to: '+14155551212',
  send_digits: '1234#',
  from: '+18668675310',
  method: 'GET'
)

puts call.start_time
// 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.factory.CallFactory;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

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);

    // Build a filter for the CallList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
    params.add(new BasicNameValuePair("To", "+14155551212"));
    params.add(new BasicNameValuePair("SendDigits", "1234#"));
    params.add(new BasicNameValuePair("From", "+18668675310"));
    params.add(new BasicNameValuePair("Method", "GET"));
    
    
    CallFactory callFactory = client.getAccount().getCallFactory();
    Call call = callFactory.create(params);
    System.out.println(call.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"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls.create(
    to="+14155551212",
    from_="+18668675310",
    url="http://demo.twilio.com/docs/voice.xml",
    send_digits="1234#",
    method="GET"
)

print(call.sid)
// Install the Java helper library from twilio.com/docs/java/install
import java.net.URI;
import java.net.URISyntaxException;

import com.twilio.Twilio;
import com.twilio.http.HttpMethod;
import com.twilio.rest.api.v2010.account.Call;
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 AUTH_TOKEN = "your_auth_token";

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

    Call call = Call
        .creator(new PhoneNumber("+14155551212"), new PhoneNumber("+18668675310"),
            new URI("http://demo.twilio.com/docs/voice.xml"))
        .setMethod(HttpMethod.GET).setSendDigits("1234#").create();

    System.out.println(call.getSid());
  }
}
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "SendDigits=1234#" \
    --data-urlencode "From=+18668675310" \
    --data-urlencode "Method=GET" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "SendDigits=1234#" \
    --data-urlencode "From=+18668675310" \
    --data-urlencode "Method=GET" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
	"sid": "CAc7a1fe47b14637f42fd94274d1907a1d",
	"date_created": "Thu, 19 Aug 2010 00:12:15 +0000",
	"date_updated": "Thu, 19 Aug 2010 00:12:15 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "+14155551212",
	"formatted_to": "(415) 555-1212",
	"from": "+18668675310",
	"formatted_from": "(866) 867-5310",
	"phone_number_sid": "PNd6b0e1e84f7b117332aed2fd2e5bbcab",
	"status": "queued",
	"start_time": null,
	"end_time": null,
	"duration": null,
	"price": null,
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2010-04-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d.json",
	"subresource_uris": {
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAc7a1fe47b14637f42fd94274d1907a1d</Sid>
		<DateCreated>Thu, 19 Aug 2010 00:25:48 +0000</DateCreated>
		<DateUpdated>Thu, 19 Aug 2010 00:25:48 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>+14155551212</To>
		<FormattedTo>(415) 555-1212</FormattedTo>
		<From>+18668675310</From>
		<FormattedFrom>(866) 867-5310</FormattedFrom>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>queued</Status>
		<StartTime/>
		<EndTime/>
		<Duration/>
		<Price/>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2010-04-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>
内線番号にダイヤルし、後の処理はTwilioに任せる
通話を発信し、プッシュ信号を送信する

内線番号にダイヤルし、後の処理はTwilioに任せる

通話を発信し、進行状況イベントを監視する

通話を発信し、すべての通話進行イベントを https://www.myapp.com/events` に送信します。

コードサンプルを読み込んでいます...
Language
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls.create(
  {
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    from: '+18668675310',
    statusCallback: 'https://www.myapp.com/events',
    statusCallbackMethod: 'POST',
    statusCallbackEvent: 'initiated ringing answered completed',
    method: 'GET',
  },
  (err, call) => {
    process.stdout.write(call.sid);
  }
);
// 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.calls
  .create({
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    from: '+18668675310',
    statusCallback: 'https://www.myapp.com/events',
    statusCallbackMethod: 'POST',
    statusCallbackEvent: ['initiated', 'ringing', 'answered', 'completed'],
    method: 'GET',
  })
  .then(call => process.stdout.write(call.sid));
// 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 options = new CallOptions();
    options.Url = "http://demo.twilio.com/docs/voice.xml";
    options.From = "+18668675310";
    options.Method = "GET";
    options.StatusCallback = "https://www.myapp.com/events";
    options.StatusCallbackMethod = "POST";
    options.StatusCallbackEvents = new string[] { "initiated", "ringing", "answered", "completed" };

    var call = twilio.InitiateOutboundCall(options);

    Console.WriteLine(call.Sid);
  }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->account->calls->create("+18668675310", "+14155551212", "http://demo.twilio.com/docs/voice.xml", array(
    "Method" => "GET",
    "StatusCallback" => "https://www.myapp.com/events",
    "StatusCallbackMethod" => "POST",
    "StatusCallbackEvent" => array("initiated", "ringing", "answered", "completed"),
    ));
echo $call->sid;
# 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

status_callback = %w[initiated ringing answered completed]
call = client.account.calls
             .create(url: 'http://demo.twilio.com/docs/voice.xml',
                     to: '+14155551212',
                     from: '+18668675310',
                     method: 'GET',
                     status_callback: 'https://www.myapp.com/events',
                     status_callback_method: 'POST',
                     status_callback_event: status_callback)
puts call.start_time
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using Twilio.Http;
using System.Collections.Generic;

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 to = new PhoneNumber("+14155551212");
        var from = new PhoneNumber("+18668675310");
        var statusCallbackEvents = new List<string>() {
            "initiated",
            "ringing",
            "answered",
            "completed" };

        var call = CallResource.Create(
            to,
            from,
            url: new Uri("http://demo.twilio.com/docs/voice.xml"),
            method: new HttpMethod("GET"),
            statusCallback: new Uri("https://www.myapp.com/events"),
            statusCallbackMethod: new HttpMethod("POST"),
            statusCallbackEvent: statusCallbackEvents);

        Console.WriteLine(call.Sid);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->calls->create(
    "+14155551212", "+18668675310",
    array(
        "url" => "http://demo.twilio.com/docs/voice.xml",
        "method" => "GET",
        "statusCallbackMethod" => "POST",
        "statusCallback" => "https://www.myapp.com/events",
        "statusCallbackEvent" => array(
            "initiated", "ringing", "answered", "completed"
        )
    )
);

echo $call->sid;
# 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)

call = client.calls.create(
    url="http://demo.twilio.com/docs/voice.xml",
    to="+14155551212",
    from_="+18668675310",
    method="GET",
    status_callback="https://www.myapp.com/events",
    status_callback_method="POST",
    status_events=["initiated", "ringing", "answered", "completed"],
)
print(call.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)

@call = @client.calls.create(
  url: 'http://demo.twilio.com/docs/voice.xml',
  to: '+14155551212',
  from: '+18668675310',
  method: 'GET',
  status_callback: 'https://www.myapp.com/events',
  status_callback_method: 'POST',
  status_callback_event: %w[initiated ringing answered completed]
)

puts @call.start_time
// 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.factory.CallFactory;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

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);

    // Build a filter for the CallList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
    params.add(new BasicNameValuePair("To", "+14155551212"));
    params.add(new BasicNameValuePair("From", "+18668675310"));
    params.add(new BasicNameValuePair("Method", "GET"));
    params.add(new BasicNameValuePair("StatusCallback", "https://www.myapp.com/events"));
    params.add(new BasicNameValuePair("StatusCallbackMethod", "POST"));
    params.add(new BasicNameValuePair("StatusCallbackEvent", "initiated"));
    params.add(new BasicNameValuePair("StatusCallbackEvent", "ringing"));
    params.add(new BasicNameValuePair("StatusCallbackEvent", "answered"));
    params.add(new BasicNameValuePair("StatusCallbackEvent", "completed"));


    CallFactory callFactory = client.getAccount().getCallFactory();
    Call call = callFactory.create(params);
    System.out.println(call.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"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls.create(
    to="+14155551212",
    from_="+18668675310",
    url="http://demo.twilio.com/docs/voice.xml",
    method="GET",
    status_callback="https://www.myapp.com/events",
    status_callback_method="POST",
    status_callback_event=["initiated", "ringing", "answered", "completed"]
)

print(call.sid)
// Install the Java helper library from twilio.com/docs/java/install
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;

import com.twilio.Twilio;
import com.twilio.http.HttpMethod;
import com.twilio.rest.api.v2010.account.Call;
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 AUTH_TOKEN = "your_auth_token";

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

    List<String> callbackEvents = Arrays.asList("initiated", "ringing", "answered", "completed");

    Call call = Call
        .creator(new PhoneNumber("+14155551212"), new PhoneNumber("+18668675310"),
            new URI("http://demo.twilio.com/docs/voice.xml"))
        .setMethod(HttpMethod.GET).setStatusCallback("https://www.myapp.com/events")
        .setStatusCallbackMethod(HttpMethod.POST).setStatusCallbackEvent(callbackEvents).create();

    System.out.println(call.getSid());
  }
}
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "From=+18668675310" \
    --data-urlencode "Method=GET" \
    --data-urlencode "StatusCallback=https://www.myapp.com/events" \
    --data-urlencode "StatusCallbackMethod=POST" \
    --data-urlencode "StatusCallbackEvent=initiated" \
    --data-urlencode "StatusCallbackEvent=ringing" \
    --data-urlencode "StatusCallbackEvent=answered" \
    --data-urlencode "StatusCallbackEvent=completed" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "From=+18668675310" \
    --data-urlencode "Method=GET" \
    --data-urlencode "StatusCallback=https://www.myapp.com/events" \
    --data-urlencode "StatusCallbackMethod=POST" \
    --data-urlencode "StatusCallbackEvent=initiated" \
    --data-urlencode "StatusCallbackEvent=ringing" \
    --data-urlencode "StatusCallbackEvent=answered" \
    --data-urlencode "StatusCallbackEvent=completed" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
	"sid": "CAc7a1fe47b14637f42fd94274d1907a1d",
	"date_created": "Thu, 19 Aug 2010 00:12:15 +0000",
	"date_updated": "Thu, 19 Aug 2010 00:12:15 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "+14155551212",
	"formatted_to": "(415) 555-1212",
	"from": "+18668675310",
	"formatted_from": "(866) 867-5310",
	"phone_number_sid": "PNd6b0e1e84f7b117332aed2fd2e5bbcab",
	"status": "queued",
	"start_time": null,
	"end_time": null,
	"duration": null,
	"price": null,
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2010-04-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d.json",
	"subresource_uris": {
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAc7a1fe47b14637f42fd94274d1907a1d</Sid>
		<DateCreated>Thu, 19 Aug 2010 00:25:48 +0000</DateCreated>
		<DateUpdated>Thu, 19 Aug 2010 00:25:48 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>+14155551212</To>
		<FormattedTo>(415) 555-1212</FormattedTo>
		<From>+18668675310</From>
		<FormattedFrom>(866) 867-5310</FormattedFrom>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>queued</Status>
		<StartTime/>
		<EndTime/>
		<Duration/>
		<Price/>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2010-04-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>
開発者のサーバーに通話進行イベントをPOSTする
通話を発信し、進行状況イベントを監視する

開発者のサーバーに通話進行イベントをPOSTする

デュアルチャンネル録音

通話を発信し、通話のそれぞれの呼を各チャンネルに録音します。

$ curl -XPOST https://api.twilio.com/2010-04-01/Accounts/AC5ef8732a3c49700934481addd5ce1659/Calls \
  -d "Url=http://demo.twilio.com/docs/voice.xml" \
  -d "To=%2B14155551212" \
  -d "From=%2B18668675309" \
  -d "Method=GET" \
  -d "Record=true" \
  -d "RecordingChannels=dual" \
  -d "RecordingStatusCallback=www.myexample.com" \
  -u 'AC5ef8732a3c49700934481addd5ce1659:{AuthToken}'

出力:

<TwilioResponse>
  <Call>
  <Sid>CAc7a1fe47b14637f42fd94274d1907a1d</Sid>
  <DateCreated>Thu, 19 Aug 2010 00:25:48 +0000</DateCreated>
  <DateUpdated>Thu, 19 Aug 2010 00:25:48 +0000</DateUpdated>
  <ParentCallSid/>
  <AccountSid>AC5ef872f6da5a21de157d80997a64bd33</AccountSid>
  <To>+14155551212</To>
  <FormattedTo>(415) 555-1212</FormattedTo>
  <From>+18668675309</From>
  <FormattedFrom>(866) 867-5309</FormattedFrom>
  <PhoneNumberSid></PhoneNumberSid>
  <Status>queued</Status>
  <StartTime/>
  <EndTime/>
  <Duration/>
  <Price/>
  <PriceUnit>USD</PriceUnit>
  <Direction>outbound-api</Direction>
  <AnsweredBy/>
  <ApiVersion>2010-04-01</ApiVersion>
  <ForwardedFrom/>
  <CallerName/>
 <Uri>/2010-04-01/Accounts/AC5ef872f6da5a21de157d80997a64bd33/Calls/CAc7a1fe47b14637f42fd94274d1907a1d</Uri>
  <SubresourceUris> <Notifications>/2010-04-01/Accounts/AC5ef872f6da5a21de157d80997a64bd33/Calls/CAc7a1fe47b14637f42fd94274d1907a1d/Notifications</Notifications>
  <Recordings>/2010-04-01/Accounts/AC5ef872f6da5a21de157d80997a64bd33/Calls/CAc7a1fe47b14637f42fd94274d1907a1d/Recordings</Recordings>
  </SubresourceUris>
  </Call>
</TwilioResponse>

応答者による処理の切り替え

(Callリソースへの)POST時のUrlパラメーターで指定されたURLにTwilioが同期リクエストを送信するとき、着信通話への応答によって開発者のアプリケーションからTwiMLをリクエストする場合とまったく同様の振る舞いをします。 このリクエスト中で渡されるパラメーターは通常のTwiML Voiceリクエストパラメーターです。

 

ヘルプが必要ですか?

誰しもが一度は考える「コーディングって難しい」。そんな時は、お問い合わせフォームから質問してください。 または、Stack Overflow でTwilioタグのついた情報から欲しいものを探してみましょう。

コードサンプルを読み込んでいます...
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls.create(
  {
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    from: '+15017122661',
  },
  (err, call) => {
    process.stdout.write(call.sid);
  }
);
// 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.calls
  .create({
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    from: '+15017122661',
  })
  .then(call => process.stdout.write(call.sid));
// 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 options = new CallOptions();
    options.Url = "http://demo.twilio.com/docs/voice.xml";
    options.To = "+14155551212";
    options.From = "+15017122661";
    var call = twilio.InitiateOutboundCall(options);
    
    Console.WriteLine(call.Sid);
  }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->account->calls->create("+15017122661", "+14155551212", "http://demo.twilio.com/docs/voice.xml", array());
echo $call->sid;
# 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

call = @client.account.calls
              .create(url: 'http://demo.twilio.com/docs/voice.xml',
                      to: '+14155551212',
                      from: '+15017122661')
puts call.to
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

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 to = new PhoneNumber("+14155551212");
        var from = new PhoneNumber("+15017122661");
        var call = CallResource.Create(to,
                                       from,
                                       url: new Uri("http://demo.twilio.com/docs/voice.xml"));

        Console.WriteLine(call.Sid);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->calls->create(
    "+14155551212", "+14158675310",
    array("url" => "http://demo.twilio.com/docs/voice.xml")
);

echo $call->sid;
# 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)

call = client.calls.create(
    url="http://demo.twilio.com/docs/voice.xml",
    to="+14155551212",
    from_="+15017122661"
)
print(call.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)

@call = @client.calls.create(
  url: 'http://demo.twilio.com/docs/voice.xml',
  to: '+14155551212',
  from: '+15017122661'
)

puts @call.sid
// 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.factory.CallFactory;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

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);

    // Build a filter for the CallList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
    params.add(new BasicNameValuePair("To", "+14155551212"));
    params.add(new BasicNameValuePair("From", "+15017122661"));
    
    
    CallFactory callFactory = client.getAccount().getCallFactory();
    Call call = callFactory.create(params);
    System.out.println(call.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"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls.create(
    to="+14155551212",
    from_="+15017122661",
    url="http://demo.twilio.com/docs/voice.xml"
)

print(call.sid)
// Install the Java helper library from twilio.com/docs/java/install
import java.net.URI;
import java.net.URISyntaxException;

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;
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 AUTH_TOKEN = "your_auth_token";

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

    Call call = Call.creator(new PhoneNumber("+14155551212"), new PhoneNumber("+15017122661"),
        new URI("http://demo.twilio.com/docs/voice.xml")).create();

    System.out.println(call.getSid());
  }
}
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "From=+14158675310" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "From=+14158675310" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
	"sid": "CAa346467ca321c71dbd5e12f627deb854",
	"date_created": "Thu, 19 Aug 2010 00:12:15 +0000",
	"date_updated": "Thu, 19 Aug 2010 00:12:15 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "+14155551212",
	"formatted_to": "(415) 555-1212",
	"from": "+14158675310",
	"formatted_from": "(415) 867-5310",
	"phone_number_sid": "PNd6b0e1e84f7b117332aed2fd2e5bbcab",
	"status": "queued",
	"start_time": null,
	"end_time": null,
	"duration": null,
	"price": null,
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2010-04-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854.json",
	"subresource_uris": {
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAa346467ca321c71dbd5e12f627deb854</Sid>
		<DateCreated>Thu, 19 Aug 2010 00:25:48 +0000</DateCreated>
		<DateUpdated>Thu, 19 Aug 2010 00:25:48 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>+14155551212</To>
		<FormattedTo>(415) 555-1212</FormattedTo>
		<From>+14158675310</From>
		<FormattedFrom>(415) 867-5310</FormattedFrom>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>queued</Status>
		<StartTime/>
		<EndTime/>
		<Duration/>
		<Price/>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2010-04-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls.create(
  {
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: 'client:charlie',
    from: '+15017122661',
  },
  (err, call) => {
    process.stdout.write(call.sid);
  }
);
// 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.calls
  .create({
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: 'client:charlie',
    from: '+15017122661',
  })
  .then(call => process.stdout.write(call.sid));
// 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 options = new CallOptions();
    options.Url = "http://demo.twilio.com/docs/voice.xml";
    options.To = "client:charlie";
    options.From = "+15017122661";
    var call = twilio.InitiateOutboundCall(options);
    
    Console.WriteLine(call.Sid);
  }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->account->calls->create("+14158675310", "client:charlie", "http://demo.twilio.com/docs/voice.xml", array());
echo $call->sid;
# 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

call = @client.account.calls
              .create(url: 'http://demo.twilio.com/docs/voice.xml',
                      to: 'client:charlie',
                      from: '+15017122661')
puts call.start_time
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

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 to = new Client("client:charlie");
        var from = new PhoneNumber("+15017122661");
        var call = CallResource.Create(to,
                                       from,
                                       url: new Uri("http://demo.twilio.com/docs/voice.xml"));

        Console.WriteLine(call.Sid);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->calls->create(
    "client:charlie", "+14158675310",
    array("url" => "http://demo.twilio.com/docs/voice.xml")
);

echo $call->sid;
# 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)

call = client.calls.create(
    url="http://demo.twilio.com/docs/voice.xml",
    to="client:charlie",
    from_="+15017122661"
)
print(call.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)

@call = @client.calls.create(
  url: 'http://demo.twilio.com/docs/voice.xml',
  to: 'client:charlie',
  from: '+15017122661'
)

puts @call.start_time
// 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.factory.CallFactory;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

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);

    // Build a filter for the CallList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
    params.add(new BasicNameValuePair("To", "client:charlie"));
    params.add(new BasicNameValuePair("From", "+15017122661"));
    
    
    CallFactory callFactory = client.getAccount().getCallFactory();
    Call call = callFactory.create(params);
    System.out.println(call.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"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls.create(
    to="client:charlie",
    from_="+15017122661",
    url="http://demo.twilio.com/docs/voice.xml"
)

print(call.sid)
// Install the Java helper library from twilio.com/docs/java/install
import java.net.URI;
import java.net.URISyntaxException;

import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;
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 AUTH_TOKEN = "your_auth_token";

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

    Call call = Call.creator(new PhoneNumber("client:charlie"), new PhoneNumber("+15017122661"),
        new URI("http://demo.twilio.com/docs/voice.xml")).create();

    System.out.println(call.getSid());
  }
}
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=client:charlie" \
    --data-urlencode "From=+15017122661" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=client:charlie" \
    --data-urlencode "From=+15017122661" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
	"sid": "CAa346467ca321c71dbd5e12f627deb854",
	"date_created": "Thu, 19 Aug 2010 00:12:15 +0000",
	"date_updated": "Thu, 19 Aug 2010 00:12:15 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "client:charlie",
	"formatted_to": "charlie",
	"from": "+14158675310",
	"formatted_from": "(415) 867-5310",
	"phone_number_sid": "PNd6b0e1e84f7b117332aed2fd2e5bbcab",
	"status": "queued",
	"start_time": null,
	"end_time": null,
	"duration": null,
	"price": null,
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2010-04-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854.json",
	"subresource_uris": {
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAa346467ca321c71dbd5e12f627deb854\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAa346467ca321c71dbd5e12f627deb854</Sid>
		<DateCreated>Thu, 19 Aug 2010 00:25:48 +0000</DateCreated>
		<DateUpdated>Thu, 19 Aug 2010 00:25:48 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>client:charlie</To>
		<FormattedTo>charlie</FormattedTo>
		<From>+14158675310</From>
		<FormattedFrom>(415) 867-5310</FormattedFrom>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>queued</Status>
		<StartTime/>
		<EndTime/>
		<Duration/>
		<Price/>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2010-04-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAa346467ca321c71dbd5e12f627deb854/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls.create(
  {
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    sendDigits: '1234#',
    from: '+18668675310',
    method: 'GET',
  },
  (err, call) => {
    process.stdout.write(call.sid);
  }
);
// 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.calls
  .create({
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    sendDigits: '1234#',
    from: '+18668675310',
    method: 'GET',
  })
  .then(call => process.stdout.write(call.sid));
// 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 options = new CallOptions();
    options.Url = "http://demo.twilio.com/docs/voice.xml";
    options.To = "+14155551212";
    options.SendDigits = "1234#";
    options.From = "+18668675310";
    options.Method = "GET";
    var call = twilio.InitiateOutboundCall(options);
    
    Console.WriteLine(call.Sid);
  }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->account->calls->create("+18668675310", "+14155551212", "http://demo.twilio.com/docs/voice.xml", array(
        "SendDigits" => "1234#",
    "Method" => "GET"
    ));
echo $call->sid;
# 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

call = @client.account.calls
              .create(url: 'http://demo.twilio.com/docs/voice.xml',
                      to: '+14155551212',
                      send_digits: '1234#',
                      from: '+18668675310',
                      method: 'GET')
puts call.start_time
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using Twilio.Http;

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 to = new PhoneNumber("+14155551212");
        var from = new PhoneNumber("+18668675310");
        var call = CallResource.Create(
            to,
            from,
            url: new Uri("http://demo.twilio.com/docs/voice.xml"),
            sendDigits: "1234#",
            method: new HttpMethod("GET"));

        Console.WriteLine(call.Sid);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->calls->create(
    "+14155551212", "+18668675310",
    array(
        "url" => "http://demo.twilio.com/docs/voice.xml",
        "sendDigits" => "1234#",
        "method" => "GET"
    )
);

echo $call->sid;
# 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)

call = client.calls.create(
    url="http://demo.twilio.com/docs/voice.xml",
    to="+14155551212",
    send_digits="1234#",
    from_="+18668675310",
    method="GET"
)
print(call.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)

call = @client.calls.create(
  url: 'http://demo.twilio.com/docs/voice.xml',
  to: '+14155551212',
  send_digits: '1234#',
  from: '+18668675310',
  method: 'GET'
)

puts call.start_time
// 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.factory.CallFactory;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

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);

    // Build a filter for the CallList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
    params.add(new BasicNameValuePair("To", "+14155551212"));
    params.add(new BasicNameValuePair("SendDigits", "1234#"));
    params.add(new BasicNameValuePair("From", "+18668675310"));
    params.add(new BasicNameValuePair("Method", "GET"));
    
    
    CallFactory callFactory = client.getAccount().getCallFactory();
    Call call = callFactory.create(params);
    System.out.println(call.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"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls.create(
    to="+14155551212",
    from_="+18668675310",
    url="http://demo.twilio.com/docs/voice.xml",
    send_digits="1234#",
    method="GET"
)

print(call.sid)
// Install the Java helper library from twilio.com/docs/java/install
import java.net.URI;
import java.net.URISyntaxException;

import com.twilio.Twilio;
import com.twilio.http.HttpMethod;
import com.twilio.rest.api.v2010.account.Call;
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 AUTH_TOKEN = "your_auth_token";

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

    Call call = Call
        .creator(new PhoneNumber("+14155551212"), new PhoneNumber("+18668675310"),
            new URI("http://demo.twilio.com/docs/voice.xml"))
        .setMethod(HttpMethod.GET).setSendDigits("1234#").create();

    System.out.println(call.getSid());
  }
}
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "SendDigits=1234#" \
    --data-urlencode "From=+18668675310" \
    --data-urlencode "Method=GET" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "SendDigits=1234#" \
    --data-urlencode "From=+18668675310" \
    --data-urlencode "Method=GET" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
	"sid": "CAc7a1fe47b14637f42fd94274d1907a1d",
	"date_created": "Thu, 19 Aug 2010 00:12:15 +0000",
	"date_updated": "Thu, 19 Aug 2010 00:12:15 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "+14155551212",
	"formatted_to": "(415) 555-1212",
	"from": "+18668675310",
	"formatted_from": "(866) 867-5310",
	"phone_number_sid": "PNd6b0e1e84f7b117332aed2fd2e5bbcab",
	"status": "queued",
	"start_time": null,
	"end_time": null,
	"duration": null,
	"price": null,
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2010-04-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d.json",
	"subresource_uris": {
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAc7a1fe47b14637f42fd94274d1907a1d</Sid>
		<DateCreated>Thu, 19 Aug 2010 00:25:48 +0000</DateCreated>
		<DateUpdated>Thu, 19 Aug 2010 00:25:48 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>+14155551212</To>
		<FormattedTo>(415) 555-1212</FormattedTo>
		<From>+18668675310</From>
		<FormattedFrom>(866) 867-5310</FormattedFrom>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>queued</Status>
		<StartTime/>
		<EndTime/>
		<Duration/>
		<Price/>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2010-04-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>
SDKバージョン:
  • 4.x
  • 5.x
レスポンス形式:
  • JSON
  • xml
SDKバージョン:
  • 6.x
  • 7.x
SDKバージョン:
  • 2.x
  • 3.x
SDKバージョン:
  • 4.x
  • 5.x
SDKバージョン:
  • 5.x
  • 6.x
SDKバージョン:
  • 4.x
  • 5.x
形式:
  • JSON
  • XML
// Download the Node helper library from twilio.com/docs/node/install
// These vars are your accountSid and authToken from twilio.com/user/account
const accountSid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const authToken = 'your_auth_token';
const client = require('twilio')(accountSid, authToken);

client.calls.create(
  {
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    from: '+18668675310',
    statusCallback: 'https://www.myapp.com/events',
    statusCallbackMethod: 'POST',
    statusCallbackEvent: 'initiated ringing answered completed',
    method: 'GET',
  },
  (err, call) => {
    process.stdout.write(call.sid);
  }
);
// 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.calls
  .create({
    url: 'http://demo.twilio.com/docs/voice.xml',
    to: '+14155551212',
    from: '+18668675310',
    statusCallback: 'https://www.myapp.com/events',
    statusCallbackMethod: 'POST',
    statusCallbackEvent: ['initiated', 'ringing', 'answered', 'completed'],
    method: 'GET',
  })
  .then(call => process.stdout.write(call.sid));
// 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 options = new CallOptions();
    options.Url = "http://demo.twilio.com/docs/voice.xml";
    options.From = "+18668675310";
    options.Method = "GET";
    options.StatusCallback = "https://www.myapp.com/events";
    options.StatusCallbackMethod = "POST";
    options.StatusCallbackEvents = new string[] { "initiated", "ringing", "answered", "completed" };

    var call = twilio.InitiateOutboundCall(options);

    Console.WriteLine(call.Sid);
  }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->account->calls->create("+18668675310", "+14155551212", "http://demo.twilio.com/docs/voice.xml", array(
    "Method" => "GET",
    "StatusCallback" => "https://www.myapp.com/events",
    "StatusCallbackMethod" => "POST",
    "StatusCallbackEvent" => array("initiated", "ringing", "answered", "completed"),
    ));
echo $call->sid;
# 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

status_callback = %w[initiated ringing answered completed]
call = client.account.calls
             .create(url: 'http://demo.twilio.com/docs/voice.xml',
                     to: '+14155551212',
                     from: '+18668675310',
                     method: 'GET',
                     status_callback: 'https://www.myapp.com/events',
                     status_callback_method: 'POST',
                     status_callback_event: status_callback)
puts call.start_time
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
using Twilio.Http;
using System.Collections.Generic;

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 to = new PhoneNumber("+14155551212");
        var from = new PhoneNumber("+18668675310");
        var statusCallbackEvents = new List<string>() {
            "initiated",
            "ringing",
            "answered",
            "completed" };

        var call = CallResource.Create(
            to,
            from,
            url: new Uri("http://demo.twilio.com/docs/voice.xml"),
            method: new HttpMethod("GET"),
            statusCallback: new Uri("https://www.myapp.com/events"),
            statusCallbackMethod: new HttpMethod("POST"),
            statusCallbackEvent: statusCallbackEvents);

        Console.WriteLine(call.Sid);
    }
}
<?php
// Get the PHP helper library from https://twilio.com/docs/libraries/php
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);

$call = $client->calls->create(
    "+14155551212", "+18668675310",
    array(
        "url" => "http://demo.twilio.com/docs/voice.xml",
        "method" => "GET",
        "statusCallbackMethod" => "POST",
        "statusCallback" => "https://www.myapp.com/events",
        "statusCallbackEvent" => array(
            "initiated", "ringing", "answered", "completed"
        )
    )
);

echo $call->sid;
# 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)

call = client.calls.create(
    url="http://demo.twilio.com/docs/voice.xml",
    to="+14155551212",
    from_="+18668675310",
    method="GET",
    status_callback="https://www.myapp.com/events",
    status_callback_method="POST",
    status_events=["initiated", "ringing", "answered", "completed"],
)
print(call.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)

@call = @client.calls.create(
  url: 'http://demo.twilio.com/docs/voice.xml',
  to: '+14155551212',
  from: '+18668675310',
  method: 'GET',
  status_callback: 'https://www.myapp.com/events',
  status_callback_method: 'POST',
  status_callback_event: %w[initiated ringing answered completed]
)

puts @call.start_time
// 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.factory.CallFactory;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.list.CallList;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

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);

    // Build a filter for the CallList
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("Url", "http://demo.twilio.com/docs/voice.xml"));
    params.add(new BasicNameValuePair("To", "+14155551212"));
    params.add(new BasicNameValuePair("From", "+18668675310"));
    params.add(new BasicNameValuePair("Method", "GET"));
    params.add(new BasicNameValuePair("StatusCallback", "https://www.myapp.com/events"));
    params.add(new BasicNameValuePair("StatusCallbackMethod", "POST"));
    params.add(new BasicNameValuePair("StatusCallbackEvent", "initiated"));
    params.add(new BasicNameValuePair("StatusCallbackEvent", "ringing"));
    params.add(new BasicNameValuePair("StatusCallbackEvent", "answered"));
    params.add(new BasicNameValuePair("StatusCallbackEvent", "completed"));


    CallFactory callFactory = client.getAccount().getCallFactory();
    Call call = callFactory.create(params);
    System.out.println(call.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"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)

call = client.calls.create(
    to="+14155551212",
    from_="+18668675310",
    url="http://demo.twilio.com/docs/voice.xml",
    method="GET",
    status_callback="https://www.myapp.com/events",
    status_callback_method="POST",
    status_callback_event=["initiated", "ringing", "answered", "completed"]
)

print(call.sid)
// Install the Java helper library from twilio.com/docs/java/install
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;

import com.twilio.Twilio;
import com.twilio.http.HttpMethod;
import com.twilio.rest.api.v2010.account.Call;
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 AUTH_TOKEN = "your_auth_token";

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

    List<String> callbackEvents = Arrays.asList("initiated", "ringing", "answered", "completed");

    Call call = Call
        .creator(new PhoneNumber("+14155551212"), new PhoneNumber("+18668675310"),
            new URI("http://demo.twilio.com/docs/voice.xml"))
        .setMethod(HttpMethod.GET).setStatusCallback("https://www.myapp.com/events")
        .setStatusCallbackMethod(HttpMethod.POST).setStatusCallbackEvent(callbackEvents).create();

    System.out.println(call.getSid());
  }
}
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "From=+18668675310" \
    --data-urlencode "Method=GET" \
    --data-urlencode "StatusCallback=https://www.myapp.com/events" \
    --data-urlencode "StatusCallbackMethod=POST" \
    --data-urlencode "StatusCallbackEvent=initiated" \
    --data-urlencode "StatusCallbackEvent=ringing" \
    --data-urlencode "StatusCallbackEvent=answered" \
    --data-urlencode "StatusCallbackEvent=completed" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
curl -XPOST https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls.json \
    --data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
    --data-urlencode "To=+14155551212" \
    --data-urlencode "From=+18668675310" \
    --data-urlencode "Method=GET" \
    --data-urlencode "StatusCallback=https://www.myapp.com/events" \
    --data-urlencode "StatusCallbackMethod=POST" \
    --data-urlencode "StatusCallbackEvent=initiated" \
    --data-urlencode "StatusCallbackEvent=ringing" \
    --data-urlencode "StatusCallbackEvent=answered" \
    --data-urlencode "StatusCallbackEvent=completed" \
    -u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
{
	"sid": "CAc7a1fe47b14637f42fd94274d1907a1d",
	"date_created": "Thu, 19 Aug 2010 00:12:15 +0000",
	"date_updated": "Thu, 19 Aug 2010 00:12:15 +0000",
	"parent_call_sid": null,
	"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
	"to": "+14155551212",
	"formatted_to": "(415) 555-1212",
	"from": "+18668675310",
	"formatted_from": "(866) 867-5310",
	"phone_number_sid": "PNd6b0e1e84f7b117332aed2fd2e5bbcab",
	"status": "queued",
	"start_time": null,
	"end_time": null,
	"duration": null,
	"price": null,
	"direction": "outbound-api",
	"answered_by": null,
	"api_version": "2010-04-01",
	"forwarded_from": null,
	"caller_name": null,
	"uri": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d.json",
	"subresource_uris": {
		"notifications": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d\/Notifications.json",
		"recordings": "\/2010-04-01\/Accounts\/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\/Calls\/CAc7a1fe47b14637f42fd94274d1907a1d\/Recordings.json"
	}
}
<TwilioResponse>
	<Call>
		<Sid>CAc7a1fe47b14637f42fd94274d1907a1d</Sid>
		<DateCreated>Thu, 19 Aug 2010 00:25:48 +0000</DateCreated>
		<DateUpdated>Thu, 19 Aug 2010 00:25:48 +0000</DateUpdated>
		<ParentCallSid/>
		<AccountSid>ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</AccountSid>
		<To>+14155551212</To>
		<FormattedTo>(415) 555-1212</FormattedTo>
		<From>+18668675310</From>
		<FormattedFrom>(866) 867-5310</FormattedFrom>
		<PhoneNumberSid></PhoneNumberSid>
		<Status>queued</Status>
		<StartTime/>
		<EndTime/>
		<Duration/>
		<Price/>
		<Direction>outbound-api</Direction>
		<AnsweredBy/>
		<ApiVersion>2010-04-01</ApiVersion>
		<ForwardedFrom/>
		<CallerName/>
		<Uri>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d</Uri>
		<SubresourceUris>
			<Notifications>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d/Notifications</Notifications>
			<Recordings>/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Calls/CAc7a1fe47b14637f42fd94274d1907a1d/Recordings</Recordings>
		</SubresourceUris>
	</Call>
</TwilioResponse>