SMS API
Exchange text and picture messages in the programming language you use.
Sign up and start buildingEnter your phone number and receive an SMS
When you click “Send SMS,” a request is sent to Twilio to deliver an SMS to the provided phone number. The server logic determines the weather forecast for San Francisco and sends a related message and graphic to the phone number.
When you click "Send SMS", an AJAX request is made that, in turn, triggers a server-side HTTP request to Twilio, which provides a number to SMS, as well as a URL of the photo to be delivered. Image media is automatically transcoded as needed to adapt to carriers and handsets.
- PHP
- Node
- Python
- Ruby
- Java
- .NET (C#)
<?php
// this line loads the library
require('/path/to/twilio-php/Services/Twilio.php');
$account_sid = 'AC5ef872f6da5a21de157d80997a64bd33';
$auth_token = '[AuthToken]';
$client = new Services_Twilio($account_sid, $auth_token);
$client->account->messages->create(array(
'To' => "+16518675309",
'From' => "+14158141829",
'Body' => "Tomorrow's forecast in Financial District, San Francisco is Clear.",
'MediaUrl' => "https://climacons.herokuapp.com/clear.png",
));
// 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 = "AC5ef872f6da5a21de157d80997a64bd33";
string AuthToken = "[AuthToken]";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage(
"+14158141829", "+16518675309",
"Tomorrow's forecast in Financial District, San Francisco is Clear.",
new string[] { "https://climacons.herokuapp.com/clear.png" } ,
null
);
Console.WriteLine(message.Sid);
}
}
// You may want to be more specific in your imports
import java.util.*;
import com.twilio.sdk.*;
import com.twilio.sdk.resource.factory.*;
import com.twilio.sdk.resource.instance.*;
import com.twilio.sdk.resource.list.*;
public class TwilioTest {
// Find your Account Sid and Token at twilio.com/user/account
public static final String ACCOUNT_SID = "AC5ef872f6da5a21de157d80997a64bd33";
public static final String AUTH_TOKEN = "[AuthToken]";
public static void main(String[]args) throws TwilioRestException {
TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
// Build the parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("To", "+16518675309"));
params.add(new BasicNameValuePair("From", "+14158141829"));
params.add(new BasicNameValuePair("Body", "Tomorrow's forecast in Financial District, San Francisco is Clear."));
params.add(new BasicNameValuePair("MediaUrl", "https://climacons.herokuapp.com/clear.png"));
MessageFactory messageFactory = client.getAccount().getMessageFactory();
Message message = messageFactory.create(params);
System.out.println(message.getSid());
}
}
// Twilio Credentials
var accountSid = 'AC5ef872f6da5a21de157d80997a64bd33';
var authToken = '[AuthToken]';
//require the Twilio module and create a REST client
var client = require('twilio')(accountSid, authToken);
client.messages.create({
to: "+16518675309",
from: "+14158141829",
body: "Tomorrow's forecast in Financial District, San Francisco is Clear.",
mediaUrl: "https://climacons.herokuapp.com/clear.png",
}, function(err, message) {
console.log(message.sid);
});
from twilio.rest import TwilioRestClient
# put your own credentials here
ACCOUNT_SID = "AC5ef872f6da5a21de157d80997a64bd33"
AUTH_TOKEN = "[AuthToken]"
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
client.messages.create(
to="+16518675309",
from_="+14158141829",
body="Tomorrow's forecast in Financial District, San Francisco is Clear.",
media_url="https://climacons.herokuapp.com/clear.png",
)
require 'rubygems' # not necessary with ruby 1.9 but included for completeness
require 'twilio-ruby'
# put your own credentials here
account_sid = 'AC5ef872f6da5a21de157d80997a64bd33'
auth_token = '[AuthToken]'
# set up a client to talk to the Twilio REST API
@client = Twilio::REST::Client.new account_sid, auth_token
@client.account.messages.create({
:from => '+14158141829',
:to => '+16518675309',
:body => 'Tomorrow\'s forecast in Financial District, San Francisco is Clear.',
:media_url => 'https://climacons.herokuapp.com/clear.png'
})
Powerful API Primitives
<Message> using custom app logic
Webhooks allow your app to define custom logic for every response. Build nearly any workflow you can imagine.
View Docs<?xml version="1.0" encoding="UTF-8"?> <Response> <Message>ahoy!</Message> </Response>Send pictures with <Media>
Send and receive pictures on all U.S. and Canadian phone numbers.
View Docs<?xml version="1.0" encoding="UTF-8"?> <Response> <Message> <Body>You need to see this to believe it...</Body> <Media>https://demo.twilio.com/owl.png</Media> </Message> </Response>Real-time status webhooks
See every step your message takes as it traverses the global telecom network.
View Docs<?xml version="1.0" encoding="UTF-8"?> <Response> <Message statusCallback="/SMSHandler.php">ahoy!</Message> </Response>
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, chat, 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.