Send WhatsApp Messages from Google Sheets Using Apps Script

WhatsApp is the messaging platform of choice for many customers and teams worldwide. With the WhatsApp Business API and Apps Script, you can send automated messages directly from a Google Sheet.

Options for sending WhatsApp via Apps Script

There are two main routes:

  1. Twilio WhatsApp API — easiest to set up, great for testing with the Twilio Sandbox.
  2. Meta (Facebook) Cloud API — official WhatsApp Business API, required for production at scale.

This article covers both.

Option 1: Twilio WhatsApp Sandbox

Twilio's sandbox lets you test WhatsApp messaging without a WhatsApp Business account.

Setup

  1. In the Twilio Console, go to Messaging > Try it out > Send a WhatsApp message.
  2. Follow the sandbox instructions (send a WhatsApp message to the Twilio number to opt in).
  3. Store your credentials:
function storeTwilioCredentials() { PropertiesService.getScriptProperties().setProperties({ 'TWILIO_ACCOUNT_SID': 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'TWILIO_AUTH_TOKEN': 'your_auth_token', 'TWILIO_WHATSAPP_FROM': 'whatsapp:+14155238886', // Twilio sandbox number }); }

Send a WhatsApp message via Twilio

function sendWhatsApp(toNumber, message) { const props = PropertiesService.getScriptProperties(); const accountSid = props.getProperty('TWILIO_ACCOUNT_SID'); const authToken = props.getProperty('TWILIO_AUTH_TOKEN'); const fromNumber = props.getProperty('TWILIO_WHATSAPP_FROM'); const url = `https://api.twilio.com/2010-04-01/Accounts/${accountSid}/Messages.json`; const options = { method: 'POST', headers: { Authorization: 'Basic ' + Utilities.base64Encode(`${accountSid}:${authToken}`), }, payload: { From: fromNumber, To: `whatsapp:${toNumber}`, Body: message, }, muteHttpExceptions: true, }; const response = UrlFetchApp.fetch(url, options); const result = JSON.parse(response.getContentText()); Logger.log(result.sid ? `Sent! SID: ${result.sid}` : `Error: ${result.message}`); }

Option 2: Meta Cloud API (Production)

For a production WhatsApp Business account, use Meta's official Cloud API.

Setup

  1. Create a Meta Developer account and a WhatsApp Business App.
  2. Get your Phone Number ID and Access Token from the Meta Developer Console.
  3. Store them securely:
function storeMetaCredentials() { PropertiesService.getScriptProperties().setProperties({ 'META_ACCESS_TOKEN': 'your_meta_access_token', 'META_PHONE_NUMBER_ID': 'your_phone_number_id', }); }

Send a template message via Meta API

WhatsApp requires pre-approved message templates for outbound messages:

function sendWhatsAppTemplate(toNumber, templateName, languageCode) { const props = PropertiesService.getScriptProperties(); const token = props.getProperty('META_ACCESS_TOKEN'); const phoneId = props.getProperty('META_PHONE_NUMBER_ID'); const url = `https://graph.facebook.com/v18.0/${phoneId}/messages`; const payload = { messaging_product: 'whatsapp', to: toNumber, // Format: '447911123456' (no + prefix) type: 'template', template: { name: templateName, language: { code: languageCode || 'en_US' }, }, }; const options = { method: 'POST', contentType: 'application/json', headers: { Authorization: `Bearer ${token}` }, payload: JSON.stringify(payload), muteHttpExceptions: true, }; const response = UrlFetchApp.fetch(url, options); const result = JSON.parse(response.getContentText()); Logger.log(JSON.stringify(result)); }

Bulk send from a Google Sheet

Set up your sheet: Name (A), Phone (B), Message (C), Sent? (D).

function sendBulkWhatsApp() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const data = sheet.getDataRange().getValues().slice(1); data.forEach((row, i) => { const [name, phone, message, sent] = row; if (sent === 'Yes' || !phone || !message) return; const personalised = message.replace('{{name}}', name); sendWhatsApp(phone, personalised); sheet.getRange(i + 2, 4).setValue('Yes'); Utilities.sleep(1000); // Avoid rate limits }); }

Tips

  • Twilio sandbox: recipients must opt in by sending a specific message to the sandbox number first. Suitable for testing only.
  • Meta API: all outbound messages to new conversations must use a pre-approved template. Free-form messages are only allowed within a 24-hour customer service window.
  • Phone numbers should be in international format without the + sign for Meta (447911123456) but with whatsapp:+44... for Twilio.
  • Both services charge per message — monitor your usage dashboards regularly when running bulk sends.