Tutorial

Send WhatsApp Messages from Google Sheets (Apps Script)

Any statistics or percentages in this article are general industry figures or illustrations, not QuackAPI measurements or promises. Results depend on your audience, consent and sending patterns. QuackAPI connects to WhatsApp as a linked device (an unofficial method), so read our risk and acceptable use policy before sending.

November 12, 20268 min read

What you will build

A Google Sheet with a list of phone numbers and messages, and a menu item called WhatsApp that sends every row that has not been sent yet. After each send the script writes the result back into the sheet, so you can see what was queued, what failed and why.

It uses Google Apps Script (the scripting language built into Google Sheets) and one HTTP request per row. There is no add-on to install and no extra service to pay for, only a connected WhatsApp number on QuackAPI.

Only message people who have agreed to hear from you. QuackAPI is a linked-device service, not Meta's official Cloud API, so WhatsApp can restrict a number it considers abusive. Read the acceptable use policy before you automate anything.

Before you start

You need three things: a Google account, a QuackAPI account with one connected device (scan the QR code from the Devices page), and your API key. The key starts with wa_ and is shown in the dashboard. You also need the numeric id of the device, which is in the device page URL, for example /devices/1.

Set up the sheet with these columns in row 1: Phone, Message, Status, Result. Put numbers in international format with digits only, for example 923001234567, and leave Status empty for rows you want to send.

ColumnWhat goes in itExample
A: PhoneRecipient number, international format923001234567
B: MessageThe text to sendHi Sara, your order #1042 has shipped.
C: StatusFilled by the script: queued or failedqueued
D: ResultMessage id or the error textmessageId 5531

Step 1: Store the API key safely

Open the sheet, choose Extensions, then Apps Script. In the editor open Project Settings (the gear icon) and scroll to Script Properties. Add two properties: QUACKAPI_KEY with your wa_ key, and QUACKAPI_DEVICE with the device id.

Keeping the key in Script Properties means it is not written into the sheet, and it is not visible to people who only have view access to the spreadsheet. Anyone who can edit the script can still read it, so only share edit access with people you trust.

Step 2: The script

Paste this into the Apps Script editor, replacing the default code, and save. It adds a WhatsApp menu when the sheet opens, loops through rows with an empty Status, sends each message with UrlFetchApp and writes the outcome back.

javascript
var API_URL = "https://quackapi.com/v1/messages/chat";

function onOpen() {
  SpreadsheetApp.getUi()
    .createMenu("WhatsApp")
    .addItem("Send unsent rows", "sendUnsentRows")
    .addToUi();
}

function cleanNumber(value) {
  // keep digits only: "+92 300 1234567" becomes "923001234567"
  return String(value).replace(/\D/g, "");
}

function sendUnsentRows() {
  var props = PropertiesService.getScriptProperties();
  var key = props.getProperty("QUACKAPI_KEY");
  var deviceId = Number(props.getProperty("QUACKAPI_DEVICE"));
  var sheet = SpreadsheetApp.getActiveSheet();
  var rows = sheet.getDataRange().getValues();

  for (var i = 1; i < rows.length; i++) {
    var phone = cleanNumber(rows[i][0]);
    var text = String(rows[i][1] || "").trim();
    var status = String(rows[i][2] || "").trim();
    if (!phone || !text || status) continue; // skip empty or already handled rows

    var response = UrlFetchApp.fetch(API_URL, {
      method: "post",
      contentType: "application/json",
      headers: { "x-api-key": key },
      payload: JSON.stringify({ deviceId: deviceId, to: phone, body: text }),
      muteHttpExceptions: true // so a 4xx does not stop the whole run
    });

    var code = response.getResponseCode();
    var data = {};
    try { data = JSON.parse(response.getContentText()); } catch (e) {}

    if (code === 200 && data.success) {
      sheet.getRange(i + 1, 3, 1, 2).setValues([["queued", "messageId " + data.messageId]]);
    } else {
      sheet.getRange(i + 1, 3, 1, 2).setValues([["failed", code + ": " + (data.message || "unknown error")]]);
    }

    SpreadsheetApp.flush();         // show progress while the script runs
    Utilities.sleep(3000);          // pause between messages
  }
}

Step 3: Run it for the first time

Reload the spreadsheet. A WhatsApp menu appears next to Help. Choose WhatsApp, then Send unsent rows. Google asks you to authorise the script the first time, because it needs permission to contact an external service and edit the sheet. This is normal for any script that calls an API.

Test with one row first, using your own number. When it works, Status shows queued and the Result column shows a message id. Queued means QuackAPI accepted the request and will send it. It does not mean the person has already received it.

Why the script pauses between messages

Sending many messages to many different people quickly is exactly what WhatsApp's automated systems look for. The three second pause in the script is a minimum, not a guarantee of safety. For larger lists, send in small batches, vary your message so it is not identical for everyone (for example, include the person's name), and stop if you see failures rising.

Apps Script also has daily limits on external requests and a maximum run time for each execution. Google publishes the current numbers on its quotas page and they differ between free and Workspace accounts, so check them if you plan to send hundreds of messages in one go. For a long list, run it a few hundred rows at a time.

Your QuackAPI plan has a daily message limit as well. When you reach it the API returns 429, the script writes failed with that code in the Result column, and you can run it again the next day.

Personalise messages with a formula

You do not need code to personalise. Keep Name and Order columns in the sheet and build the message with a formula in column B, for example: ="Hi " & E2 & ", your order #" & F2 & " has shipped." The script simply sends whatever the cell shows.

Run it automatically on a schedule

In the Apps Script editor open Triggers (the clock icon) and add a time-driven trigger for sendUnsentRows, for example every hour. Rows added to the sheet with an empty Status are sent on the next run. Be careful with this: an automatic trigger means nobody reviews the messages before they go out, so keep the Message column controlled and make sure every number in the sheet has opted in.

If you want to react to replies instead of only sending, set a webhook URL on the device and QuackAPI will POST incoming messages and delivery results to it. See the webhook reference for the payloads.

Troubleshooting

These are the errors people hit most often when they first set this up.

What you seeCauseFix
401 in the Result columnAPI key missing or wrongCheck the QUACKAPI_KEY script property. It must start with wa_ and have no spaces.
404: Device not foundWrong device idUse the numeric id from the device page URL, not the device name.
403 device disconnectedThe WhatsApp session was logged outOpen the device page and scan the QR code again.
409 device not readyThe device is still starting upWait a minute and run again. Only rows with an empty Status are retried, so clear Status on failed rows to retry them.
400 validation errorBad number or empty messageUse digits only in international format, with no leading 0 or plus sign.
429Daily message limit reachedContinue tomorrow or upgrade the plan.

Frequently asked questions

Can I send WhatsApp messages from Google Sheets for free?
Apps Script and Google Sheets are free to use within Google's quotas. You need a QuackAPI account and a connected WhatsApp number to actually send. See the pricing page for current plans.
Does this use the official WhatsApp Business API?
No. QuackAPI sends through WhatsApp's linked-devices feature with a QR code, so you do not need Meta business verification or message templates. The trade-off is that WhatsApp can restrict a number that behaves like a spammer.
Can I send images or PDFs from a sheet?
Yes. Change the endpoint to /v1/messages/image or /v1/messages/document and send a public file URL in the image or document field. The docs list every field.
How do I stop it from sending the same row twice?
The script only sends rows whose Status cell is empty and writes queued or failed immediately after each attempt. Do not clear Status on rows you do not want to resend.

Where to go next

Sending from a script is the simplest start. If you prefer a visual builder, see how to send WhatsApp messages from n8n. For code in a full application, read the Node.js or Python guide, and see the API quick start for the full request reference.

Ready to get started?

Send WhatsApp Messages via API — Free

No Meta Business verification. No credit card. Connect your WhatsApp in under 2 minutes and start sending messages through the REST API.

Related Articles