Skip to contentSkip to navigationSkip to topbar
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 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

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 way to send your first WhatsApp message, check out our quickstarts!

Sending a Message with the Twilio API for WhatsAppLink to code sample: Sending a Message with the Twilio API for WhatsApp
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createMessage() {
11
const message = await client.messages.create({
12
body: "Your appointment is coming up on July 21 at 3PM",
13
from: "whatsapp:+552120420682",
14
to: "whatsapp:+13233633791",
15
});
16
17
console.log(message.body);
18
}
19
20
createMessage();

Output

1
{
2
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"api_version": "2010-04-01",
4
"body": "Your appointment is coming up on July 21 at 3PM",
5
"date_created": "Thu, 24 Aug 2023 05:01:45 +0000",
6
"date_sent": "Thu, 24 Aug 2023 05:01:45 +0000",
7
"date_updated": "Thu, 24 Aug 2023 05:01:45 +0000",
8
"direction": "outbound-api",
9
"error_code": null,
10
"error_message": null,
11
"from": "whatsapp:+552120420682",
12
"num_media": "0",
13
"num_segments": "1",
14
"price": null,
15
"price_unit": null,
16
"messaging_service_sid": "MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
17
"sid": "SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
18
"status": "queued",
19
"subresource_uris": {
20
"media": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Media.json"
21
},
22
"tags": {
23
"campaign_name": "Spring Sale 2022",
24
"message_type": "cart_abandoned"
25
},
26
"to": "whatsapp:+13233633791",
27
"uri": "/2010-04-01/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Messages/SMaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.json"
28
}

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.