Make your first outgoing phone call with just a few lines of code. Add a few more and your app can respond to incoming callers. Then choose your programming for quick and confident deployment.
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);
async function createCall() {
const call = await client.calls.create({
from: "+15558675310",
to: "+15017122661",
url: "http://demo.twilio.com/docs/voice.xml",
});
console.log(call.sid);
}
createCall();
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client
# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)
call = client.calls.create(
from_="+15558675310",
to="+15017122661",
url="http://demo.twilio.com/docs/voice.xml",
)
print(call.sid)
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using System.Threading.Tasks;
class Program {
public static async Task Main(string[] args) {
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
TwilioClient.Init(accountSid, authToken);
var call = await CallResource.CreateAsync(
from: new Twilio.Types.PhoneNumber("+15558675310"),
to: new Twilio.Types.PhoneNumber("+15017122661"),
url: new Uri("http://demo.twilio.com/docs/voice.xml"));
Console.WriteLine(call.Sid);
}
}
// Install the Java helper library from twilio.com/docs/java/install
import java.net.URI;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Call;
public class Example {
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");
public static void main(String[] args) {
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
Call call = Call.creator(new com.twilio.type.PhoneNumber("+15017122661"),
new com.twilio.type.PhoneNumber("+15558675310"),
URI.create("http://demo.twilio.com/docs/voice.xml"))
.create();
System.out.println(call.getSid());
}
}
<?php
// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";
use Twilio\Rest\Client;
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);
$call = $twilio->calls->create(
"+15017122661", // To
"+15558675310", // From
["url" => "http://demo.twilio.com/docs/voice.xml"]
);
print $call->sid;
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'rubygems'
require 'twilio-ruby'
# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)
call = @client
.api
.v2010
.calls
.create(
from: '+15558675310',
to: '+15017122661',
url: 'http://demo.twilio.com/docs/voice.xml'
)
puts call.sid
# Install the twilio-cli from https://twil.io/cli
twilio api:core:calls:create \
--from +15558675310 \
--to +15017122661 \
--url http://demo.twilio.com/docs/voice.xml
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Calls.json" \
--data-urlencode "From=+15558675310" \
--data-urlencode "To=+15017122661" \
--data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN