Twilio API for WhatsApp Beta

Send and receive messages on WhatsApp using a simple REST API trusted by millions of developers.

Send a WhatsApp message

Use the same Programmable SMS API you know and trust to send WhatsApp messages. WhatsApp helper libraries are available in PHP, Node, Python, Ruby and Java.

View Docs

Send a WhatsApp Message

  • CuRL
  • PHP
  • Node
  • Python
  • Ruby
  • Java
  • .NET (C#)
curl -X "POST" \
	--data-urlencode 'To=whatsapp:+13233633791' \
	--data-urlencode 'From=whatsapp:+18007778888 \
	--data-urlencode 'Body=Hi Joe! Your order D45987AB will arrive on 8/12/2018 before 8 pm.' \
	-u {Account Sid}:{Auth Token} \
	https://api.twilio.com/2010-04-01/Accounts/{AccountSID}/Messages.json
<?php

// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "AC5ef872f6da5a21de157d80997a64bd33";
$token = "your_auth_token";
$client = new Client($sid, $token);
$client->messages->create(
    "whatsapp:+13233633791",
    array(
        'from' => "whatsapp:+18007778888",
        'body' => "Hi Joe! Your order D45987AB will arrive on 8/12/2018 before 8 pm.",
    )
);
// Twilio Credentials
const accountSid = 'AC5ef872f6da5a21de157d80997a64bd33';
const authToken = 'your_auth_token';

// require the Twilio module and create a REST client
const client = require('twilio')(accountSid, authToken);

client.messages
	.create({
		to: 'whatsapp:+13233633791',
		from: 'whatsapp:+18007778888',
		body: "Hi Joe! Your order D45987AB will arrive on 8/12/2018 before 8 pm.",
	})
	.then((message) => console.log(message.sid));
from twilio.rest import Client

# put your own credentials here
account_sid = "AC5ef872f6da5a21de157d80997a64bd33"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)
client.messages.create(
    to="+whatsapp:+13233633791",
    from_="+whatsapp:+18007778888",
    body="Hi Joe! Your order D45987AB will arrive on 8/12/2018 before 8 pm.")
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 => '+whatsapp:+18007778888',
    :to => '+whatsapp:+13233633791',
    :body => 'Hi Joe! Your order D45987AB will arrive on 8/12/2018 before 8 pm.',
})
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "AC5ef872f6da5a21de157d80997a64bd33";
  public static final String AUTH_TOKEN = "your_auth_token";
  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
    Message message = Message
      .creator(new PhoneNumber("+whatsapp:+13233633791"), new PhoneNumber("+whatsapp:+18007778888"),
        "Hi Joe! Your order D45987AB will arrive on 8/12/2018 before 8 pm.")
      .create();
    System.out.println(message.getSid());
  }
}
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
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 = "AC5ef872f6da5a21de157d80997a64bd33";
    const string authToken = "your_auth_token";
    TwilioClient.Init(accountSid, authToken);
    var to = new PhoneNumber("+whatsapp:+13233633791");
    var message = MessageResource.Create(
      to,
      from: new PhoneNumber("+whatsapp:+18007778888"),
      body: "Hi Joe! Your order D45987AB will arrive on 8/12/2018 before 8 pm.",
      mediaUrl: mediaUrl);
    Console.WriteLine(message.Sid);
  }
}

Respond to a WhatsApp message

Use TwiML on your own server, TwiMLBins, Functions and even Studio to build flows to easily respond to incoming messages.

View Docs


<Response>
    <Message>Hello from WhatsApp!</Message>
</Response>

Real-time status webhooks

Set status callbacks to instantly check if your messages were delivered or opened by the user.

View Docs

<Response>
	<Message statusCallback="/deliveryHandler">That’s a great question! Let me find someone that can answer it.</Message>
</Response>

Send Media Messages Coming Soon

Send images, audio, video and pdf files via WhatsApp, similar to doing the same with MMS.

Send Media Message

  • CuRL
  • PHP
  • Node
  • Python
  • Ruby
  • Java
  • .NET (C#)
curl -X "POST" \
    --data-urlencode 'To=whatsapp:+13233633791' \
    --data-urlencode 'From=whatsapp:+18007778888' \
    --data-urlencode 'Body=Hi Joe! Please find your boarding pass attached. Flight OA2345 departs at 11 pm PST.'
    --data-urlencode 'MediaUrl= https://https://bushes-cheerful-8100.twil.io/assets/2-OwlAir-Upcoming-Trip.PNG' \
    -u {Account Sid}:{Auth Token} \
    https://api.twilio.com/2010-04-01/Accounts/{AccountSID}/Messages.json
<?php

// Get the PHP helper library from twilio.com/docs/php/install
require_once '/path/to/vendor/autoload.php'; // Loads the library
use Twilio\Rest\Client;

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "AC5ef872f6da5a21de157d80997a64bd33";
$token = "your_auth_token";
$client = new Client($sid, $token);
$client->messages->create(
    "whatsapp:+13233633791",
    array(
        'from' => "whatsapp:+18007778888",
        'body' => "Hi Joe! Please find your boarding pass attached. Flight OA2345 departs at 11 pm PST.",
        'mediaUrl' => "https://emerald-coral-3661.twil.io/assets/2-OwlAir-Upcoming-Trip.PNG",
    )
);
// Twilio Credentials
const accountSid = 'AC5ef872f6da5a21de157d80997a64bd33';
const authToken = 'your_auth_token';

// require the Twilio module and create a REST client
const client = require('twilio')(accountSid, authToken);

client.messages
    .create({
        to: 'whatsapp:+13233633791',
        from: 'whatsapp:+18007778888',
        body: "Hi Joe! Please find your boarding pass attached. Flight OA2345 departs at 11 pm PST.",
        mediaUrl: 'https://emerald-coral-3661.twil.io/assets/2-OwlAir-Upcoming-Trip.PNG',
    })
    .then((message) => console.log(message.sid));
from twilio.rest import Client

# put your own credentials here
account_sid = "AC5ef872f6da5a21de157d80997a64bd33"
auth_token = "your_auth_token"
client = Client(account_sid, auth_token)
client.messages.create(
    to="+whatsapp:+13233633791",
    from_="+whatsapp:+18007778888",
    body="Hi Joe! Please find your boarding pass attached. Flight OA2345 departs at 11 pm PST.",
    media_url="https://emerald-coral-3661.twil.io/assets/2-OwlAir-Upcoming-Trip.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 => '+whatsapp:+18007778888',
  :to => '+whatsapp:+13233633791',
  :body => 'Hi Joe! Please find your boarding pass attached. Flight OA2345 departs at 11 pm PST.',
  :media_url => 'https://emerald-coral-3661.twil.io/assets/2-OwlAir-Upcoming-Trip.PNG'
})
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
public class Example {
  // Find your Account Sid and Token at twilio.com/user/account
  public static final String ACCOUNT_SID = "AC5ef872f6da5a21de157d80997a64bd33";
  public static final String AUTH_TOKEN = "your_auth_token";
  public static void main(String[] args) {
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
    Message message = Message
      .creator(new PhoneNumber("+whatsapp:+13233633791"), new PhoneNumber("+whatsapp:+18007778888"),
        "Hi Joe! Your order D45987AB will arrive on 8/12/2018 before 8 pm.")
      .create();
    System.out.println(message.getSid());
  }
}
using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;
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 = "AC5ef872f6da5a21de157d80997a64bd33";
    const string authToken = "your_auth_token";
    TwilioClient.Init(accountSid, authToken);
    var mediaUrl = new List() {
      new Uri( "https://emerald-coral-3661.twil.io/assets/2-OwlAir-Upcoming-Trip.PNG" )
    };
    var to = new PhoneNumber("+whatsapp:+13233633791");
    var message = MessageResource.Create(
      to,
      from: new PhoneNumber("+whatsapp:+18007778888"),
      body: "Hi Joe! Please find your boarding pass attached. Flight OA2345 departs at 11 pm PST.",
      mediaUrl: mediaUrl);
    Console.WriteLine(message.Sid);
  }
}

Developer tools designed to get you to production faster

Twilio Sandbox for WhatsApp

Start testing with whitelisted phone numbers. Request access to a WhatsApp Business Profile when you’re ready to move to production.

Functions

Save development time using a serverless environment to build and run the code powering your WhatsApp application.

Debugging Tools

Troubleshoot your application easily. Use the API Explorer to reproduce issues and the Debugger to diagnose and fix them.

Scale fast and reliably with reduced operational dependencies

Send your first WhatsApp message with three lines of code. Twilio deploys and scales your WhatsApp containers for you.

Leverage an enterprise-grade API platform that powers billions of interactions a day with 99.999% uptime.

Port your application logic to another messaging channel using the same API and just a few lines of code.

See the Twilio API for WhatsApp in action

WhatsApp Emoji Translator

  1. Click this link on mobile

    Or scan this QR code to open up a chat window in WhatsApp

  2. Type the word you want an emoji for. Try ‘apple’ or ‘popcorn’.

  3. The app will send you back 🍎 or 🍿
    (and sometimes a different one each time!).

See how to build it