Enter your number and receive a call

  • What's Happening
  • Technical Version

When you start the phone call, this code makes a request to Twilio providing both a phone number to call, and a server location that will provide TwiML instructions on how to route the phone call.

This call logic relies on a number of TwiML verbs including <Say> to speak audio to the caller, <Gather> to take dialpad input from the user, and <Play> to play audio back to the user.

  • PHP
  • Node
  • Python
  • Ruby
  • Java
  • .NET (C#)
<?php

require 'Services/Twilio.php';

$accountSid = 'ACXXXXXXXXXXXXXXXXX';
$authToken = 'YYYYYYYYYYYYYYYYYY';

$client = new Services_Twilio($sid, $token, $version);

$phonenumber = '+14154834499';

try {
  $call = $client->account->calls->create(
    $phonenumber,
    '555-123-4567',
    'http://ahoy.twilio.com/voice/api/demo'
  );
  echo 'Started call: ' . $call->sid;
} catch (Exception $e) {
  echo 'Error: ' . $e->getMessage();
}
@using Twilio;

@{
  string accountSid = "ACXXXXXXXXXXXXXXXXX";
  string authToken = "YYYYYYYYYYYYYYYYYY";

  string phonenumber = "+14154834499";

  var client = new TwilioRestClient(accountSid, authToken);

  var call = client.InitiateOutboundCall(
    phonenumber,
    "555-123-4567",
    "http://ahoy.twilio.com/voice/api/demo"
  );

  if (call.RestException == null)
    Response.Write(string.Format("Started call: {0}", call.Sid));
  } else {
    Response.Write(string.Format("Error: {0}",
    	call.RestException.Message));
  }
}
import java.util.Map;
import java.util.HashMap;

import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.instance.Account;
import com.twilio.sdk.resource.instance.Call;
import com.twilio.sdk.resource.factory.CallFactory;

public class MakeCall {

  public static final String ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX";
  public static final String AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY";

  public static void main(String[] args) throws TwilioRestException {

    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
    Account mainAccount = client.getAccount();
    CallFactory callFactory = mainAccount.getCallFactory();
    Map<String, String> callParams = new HashMap<String, String>();
    callParams.put("From", "+14154834499");
    callParams.put("To", "555-123-4567");
    callParams.put("Url", "http://ahoy.twilio.com/voice/api/demo");
    Call call = callFactory.create(callParams);
    System.out.println(call.getSid());
  }
}
var client = require('twilio')('ACXXXXXXXXXXXXXXXXX', 'YYYYYYYYYYYYYYYYYY');

client.makeCall({
  from: '+14154834499',
  to: '555-123-4567',
  url: 'http://ahoy.twilio.com/voice/api/demo'
}, function (err, responseData) {
  console.log(responseData);
});
from twilio.rest import TwilioRestClient

account_sid = "ACXXXXXXXXXXXXXXXXX"
auth_token = "YYYYYYYYYYYYYYYYYY"
client = TwilioRestClient(account_sid, auth_token)

call = client.calls.create(
  from_="+14154834499",
  to="555-123-4567",
  url="http://ahoy.twilio.com/voice/api/demo")
print call.sid
require 'rubygems'
require 'twilio-ruby'

account_sid = 'ACXXXXXXXXXXXXXXXXX'
auth_token = 'YYYYYYYYYYYYYYYYYY'

@client = Twilio::REST::Client.new account_sid, auth_token

@call = @client.account.calls.create(
  :from => '+14154834499',
  :to => '555-123-4567',
  :url => 'http://ahoy.twilio.com/voice/api/demo'
)
The Twilio advantage
  • Communicate reliably

    Experience a 99.95% uptime SLA made possible with automated failover and zero-maintenance windows.

  • Operate at scale

    Extend the same app you write once to new markets with configurable features for localization and compliance.

  • Many channels

    Use the same platform you know for voice, SMS, video, IP messaging, two-factor authentication, and more.

  • No shenanigans

    Get to market faster with pay-as-you-go pricing, free support, and the freedom to scale up or down without contracts.