Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this pageProducts used

Twilio API for WhatsApp Tutorials


The Twilio API for WhatsApp is the quickest way to add two-way messaging on WhatsApp into your web application. With the same Twilio API you use for SMS, you can easily add WhatsApp capabilities to your application by changing just two lines of code.

If you're feeling overwhelmed by the possibilities now that WhatsApp is finally programmable, worry no more! To get you started, we've created these tutorials for common use cases that are well-suited for WhatsApp.


Twilio API for WhatsApp Tutorials and Guides

twilio-api-for-whatsapp-tutorials-and-guides page anchor

Our Twilio API for WhatsApp Tutorials and Guides show you how to use WhatsApp to power common messaging use cases. Tutorials have code samples in six languages to help you get building faster, with the tools you already use.


Sending a Message with the Twilio API for WhatsApp

sending-a-message-with-the-twilio-api-for-whatsapp page anchor

Just how easy is it to send messages via WhatsApp and the Twilio API? Once you're set up, here's how you'll send messages for 6 web languages and cURL. If you're looking for an even quicker and easier way to send your first WhatsApp message, check out our quickstarts!

Sending a Message with the Twilio API for WhatsApp

sending-a-message-with-the-twilio-api-for-whatsapp-1 page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_16
// Download the helper library from https://www.twilio.com/docs/node/install
_16
import twilio from "twilio";
_16
_16
// Find your Account SID and Auth Token at twilio.com/console
_16
// and set the environment variables. See http://twil.io/secure
_16
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_16
const authToken = process.env.TWILIO_AUTH_TOKEN;
_16
const client = twilio(accountSid, authToken);
_16
_16
const message = await client.messages.create({
_16
body: "Your appointment is coming up on July 21 at 3PM",
_16
from: "whatsapp:+552120420682",
_16
to: "whatsapp:+13233633791",
_16
});
_16
_16
console.log(message.body);

Output

_28
{
_28
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"api_version": "2010-04-01",
_28
"body": "Your appointment is coming up on July 21 at 3PM",
_28
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
_28
"direction": "outbound-api",
_28
"error_code": null,
_28
"error_message": null,
_28
"from": "whatsapp:+552120420682",
_28
"num_media": "0",
_28
"num_segments": "1",
_28
"price": null,
_28
"price_unit": null,
_28
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_28
"status": "queued",
_28
"subresource_uris": {
_28
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
_28
},
_28
"tags": {
_28
"campaign_name": "Spring Sale 2022",
_28
"message_type": "cart_abandoned"
_28
},
_28
"to": "whatsapp:+13233633791",
_28
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
_28
}


Rate this page: