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.
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.
| Column | What goes in it | Example |
|---|---|---|
| A: Phone | Recipient number, international format | 923001234567 |
| B: Message | The text to send | Hi Sara, your order #1042 has shipped. |
| C: Status | Filled by the script: queued or failed | queued |
| D: Result | Message id or the error text | messageId 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.
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 see | Cause | Fix |
|---|---|---|
| 401 in the Result column | API key missing or wrong | Check the QUACKAPI_KEY script property. It must start with wa_ and have no spaces. |
| 404: Device not found | Wrong device id | Use the numeric id from the device page URL, not the device name. |
| 403 device disconnected | The WhatsApp session was logged out | Open the device page and scan the QR code again. |
| 409 device not ready | The device is still starting up | Wait a minute and run again. Only rows with an empty Status are retried, so clear Status on failed rows to retry them. |
| 400 validation error | Bad number or empty message | Use digits only in international format, with no leading 0 or plus sign. |
| 429 | Daily message limit reached | Continue tomorrow or upgrade the plan. |
Frequently asked questions
Can I send WhatsApp messages from Google Sheets for free?
Does this use the official WhatsApp Business API?
Can I send images or PDFs from a sheet?
How do I stop it from sending the same row twice?
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.