Send WhatsApp messages from Google Sheets (Apps Script)

Send a WhatsApp template message to each row of a Google Sheet with a short Apps Script. A menu button, a status column, no double sends if the script is re-run, and the errors that should stop a run.

November 13, 2026 · 10 min read

A Google Sheet is where many small teams already keep their customers: a name, a phone number, one detail such as an order number or a date. This guide adds a WhatsApp menu to that sheet. One click sends an approved template message to every row that has not been sent yet, and writes the result back into the sheet.

SendFromChat is an independent product and is not affiliated with Meta, WhatsApp or Google. It runs on Meta's official WhatsApp Cloud API; you keep your own WhatsApp Business account. Google limits below come from Google's Apps Script quotas and triggers pages, read on 13 Nov 2026. SendFromChat endpoints, fields and errors come from our REST API reference, read the same day.

What was tested: the script below was run in Node against a fake version of Google's SpreadsheetApp, UrlFetchApp, Utilities and PropertiesService, and a fake SendFromChat API. 13 checks passed: a successful send, a bad phone number, an opted_out row, a re-run after a crash (the same request is replayed, not sent twice), a warmup_limit stop, the server being down, a test key, and a missing or wrong key. Not run: inside Google Apps Script itself, against a live SendFromChat key, or against Meta. Try it on a copy of your sheet, with a test key and your own phone number first.

The short version

  • The script reads rows from the active sheet and sends a template for each row whose status column is empty (why a template).
  • Every request carries an Idempotency-Key built from the row number and a hash of the request body. Re-running after a crash does not send a second message for a row that went through.
  • A 202 means accepted, not delivered or read. The sheet says accepted, and the message id is saved so you can check it later.
  • Errors about one row (a bad number, opted_out) mark that row and move on. Errors about the whole account (unauthorized, sending_paused, no_number, warmup_limit) stop the run.
  • Send only to people who agreed to hear from you (opt-in).

What you need first

  1. A SendFromChat workspace with a number connected (getting started). A test key also needs a connected number (409 no_number otherwise). If the connect step stalls, see the Facebook login step explained and a number that won't connect or a code that doesn't arrive.
  2. An approved template with two variables, here called order_shipped (templates, why templates get rejected). Example text: Hi {{1}}, an update on your order: {{2}}. Reply to this message if you need a hand.
  3. A SendFromChat test key (sfc_test_…) from the Developers page while you build. It runs the checks a real send would, then stops; nothing is sent (details). Switch to a live key (sfc_live_…) when it works.
  4. A card on your WhatsApp Business account at Meta before you can send templates. Meta bills it directly, separate from your SendFromChat plan. The 30-day trial itself needs no card.
  5. Consent from every person on the sheet.

1. Lay out the sheet

Use one header row, then one person per row:

A B C D E
phone name detail status message id
+491701234567 Ana Order 4821 has shipped

Format column A as Plain text (Format > Number > Plain text) and type numbers with the + and country code. Otherwise Sheets can turn +49… into a number and drop the plus. The script strips spaces, dashes and brackets, and marks any row that is still not a valid international number as failed: bad number (number format). Leave D and E empty: the script fills them.

2. Add the script

In the sheet, open Extensions > Apps Script, replace the contents of Code.gs with this, and change TEMPLATE and LANGUAGE to your own.

const API_URL = 'https://sendfromchat.com/api/v1/messages';
const TEMPLATE = 'order_shipped'; // an approved template with two variables: {{1}} name, {{2}} detail
const LANGUAGE = 'en_US';
const MAX_PER_RUN = 100;          // keeps one run well inside Apps Script's 6-minute limit
const PAUSE_MS = 300;             // our own pause between sends, not a documented API limit
const COL = { phone: 1, name: 2, detail: 3, status: 4, id: 5 };
// Errors that mean "stop the whole run", not "this row is bad"
const STOP_TYPES = ['unauthorized', 'sending_paused', 'live_key_required',
  'no_number', 'warmup_limit', 'request_in_progress'];

function onOpen() {
  SpreadsheetApp.getUi().createMenu('WhatsApp')
    .addItem('Send rows with an empty status', 'sendPending')
    .addToUi();
}

function toE164(raw) {
  const s = String(raw).replace(/[\s\-().]/g, '');
  return /^\+[1-9]\d{6,14}$/.test(s) ? s : null;
}

function hex8(text) {
  const bytes = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_256, text);
  return bytes.map(function (b) { return (b < 0 ? b + 256 : b).toString(16).padStart(2, '0'); })
    .join('').slice(0, 8);
}

function sendPending() {
  const key = PropertiesService.getScriptProperties().getProperty('SFC_API_KEY');
  if (!key) throw new Error('Add SFC_API_KEY under Project Settings > Script properties.');

  const sheet = SpreadsheetApp.getActiveSheet();
  const lastRow = sheet.getLastRow();
  if (lastRow < 2) return;
  const rows = sheet.getRange(2, 1, lastRow - 1, 5).getValues();

  let accepted = 0, failed = 0, stoppedBy = '';
  for (let i = 0; i < rows.length && accepted + failed < MAX_PER_RUN; i++) {
    const rowNumber = i + 2;
    const phone = rows[i][COL.phone - 1], name = rows[i][COL.name - 1];
    const detail = rows[i][COL.detail - 1], status = rows[i][COL.status - 1];
    if (status !== '' || phone === '') continue;

    const to = toE164(phone);
    if (!to) { setStatus(sheet, rowNumber, 'failed: bad number', ''); failed++; continue; }

    const body = JSON.stringify({
      to: to,
      template: { name: TEMPLATE, language: LANGUAGE, variables: [String(name), String(detail)] }
    });
    // Same row and same content give the same key, so a re-run after a crash is not a second send
    const idempotencyKey = 'sheet-row-' + rowNumber + '-' + hex8(body);

    let response;
    try {
      response = UrlFetchApp.fetch(API_URL, {
        method: 'post',
        contentType: 'application/json',
        headers: { Authorization: 'Bearer ' + key, 'Idempotency-Key': idempotencyKey },
        payload: body,
        muteHttpExceptions: true
      });
    } catch (err) {
      stoppedBy = 'network: ' + err.message; // row stays empty, run it again later
      break;
    }

    const code = response.getResponseCode();
    let data = {};
    try { data = JSON.parse(response.getContentText()); } catch (e) { /* not JSON */ }

    if (code === 202) { setStatus(sheet, rowNumber, 'accepted', data.id); accepted++; }
    else if (code === 200 && data.status === 'test') { setStatus(sheet, rowNumber, 'test ok', ''); accepted++; }
    else {
      const type = (data.error && data.error.type) || ('http ' + code);
      if (STOP_TYPES.indexOf(type) !== -1 || code >= 500) { stoppedBy = type; break; }
      setStatus(sheet, rowNumber, 'failed: ' + type, ''); // e.g. opted_out, template_not_approved
      failed++;
    }
    Utilities.sleep(PAUSE_MS);
  }

  const note = accepted + ' accepted, ' + failed + ' failed' + (stoppedBy ? ', stopped: ' + stoppedBy : '');
  SpreadsheetApp.getActive().toast(note, 'WhatsApp', 10);
}

function setStatus(sheet, row, status, messageId) {
  sheet.getRange(row, COL.status, 1, 2).setValues([[status, messageId || '']]);
  SpreadsheetApp.flush();
}

Then store the key. Open Project Settings > Script properties, add a property named SFC_API_KEY and paste your test key as the value. Do not paste the key into the code or into a cell: anyone who can see the sheet or the script could read it.

3. Run it

Reload the sheet so the WhatsApp menu appears, then choose WhatsApp > Send rows with an empty status. The first time, Google asks you to authorise the script. With a test key each row shows test ok; nothing is sent. With a live key each row shows accepted and its message id. A toast at the end shows the totals and, if the run stopped early, why.

Why a button and not a trigger on every edit: Google's triggers page says simple triggers such as onOpen cannot access services that require authorization and cannot run for more than 30 seconds, and installable triggers need setting up. A menu click you control is simpler and means nothing is sent by accident. If you later add a time-driven installable trigger, test it on a copy first; we did not test one for this guide.

4. Why it is built this way

One run is capped at 100 rows. Google documents a 6-minute limit per execution and a daily limit on URL Fetch calls (20,000 on consumer accounts, 100,000 on Google Workspace accounts, at the time we read the page). MAX_PER_RUN keeps a run short; click the menu again for the next batch. The 300 ms pause is our own choice, not an API limit.

New numbers have a daily cap. Template sends from a new number are capped at 50, 100, then 200 a day for the first three days (limits). Going over returns 429 warmup_limit. The script stops there and leaves the remaining rows empty, so tomorrow's run picks them up.

Retries do not double-send. Our reference says a retry with the same Idempotency-Key and body returns the first response with Idempotent-Replayed: true instead of sending again, and that reusing a key with a different body returns idempotency_mismatch. The key here is the row number plus an 8-character hash of the body. If Apps Script times out after the request went out but before the status was written, the next run builds the same key and gets the first response. If you change the template or the row's text, the key changes too, which is a new send on purpose. A 409 request_in_progress means the same key is still running; the script stops, and a later run is fine.

Row errors and account errors are different. opted_out and template_not_approved belong to one row or one template, so that row is marked failed: … and the run continues. unauthorized (wrong or revoked key), sending_paused (trial ended or plan limit reached), live_key_required, no_number and warmup_limit will fail for every row, so the run stops. Branch on error.type, not the message text. All the types are in the errors table.

A failed row is not retried by itself. To send it again, fix the cause and clear its status cell. Do not clear the cells of rows that say accepted: that is how a message goes out twice.

5. Know whether it arrived

accepted only means SendFromChat took the request. To see what happened next, read GET /messages/{id} with the id in column E, or subscribe to the message.status webhook. A message moves from sent to delivered to read, or ends as failed with a reason (track sent, delivered and read). If people reply, see receive WhatsApp replies with webhooks; you can answer in free-form text within 24 hours of their last message.

Before you use a live key

  • Send to your own number first, then to two or three colleagues who agreed.
  • Check that every person on the sheet opted in, and keep the record. A bulk send to people who did not agree can get your WhatsApp number flagged. See sending in bulk without getting banned.
  • Anyone who has opted out in SendFromChat shows up as failed: opted_out. Do not clear that status and retry.
  • Keep the key private. If the sheet is shared with people who should not send, they can still run the script from its menu, so share it carefully or keep the sending sheet to yourself.

Try it

Make a copy of your sheet, add the script and a test key, put your own number in row 2 and run the menu. You should see test ok. Then switch to a live key and send that one row to yourself before the rest.

Already on a trial? Connect your number first: open Connect WhatsApp in the dashboard and click Continue with Facebook. A test key needs a connected number too.

Do not have an account yet? There is a 30-day free trial, no card needed to start: sign up. For a no-code version of the same job, see send a WhatsApp broadcast from a spreadsheet.

Sources

  • Google Apps Script quotas: URL Fetch calls per day (20,000 consumer, 100,000 Workspace) and 6-minute execution time. Read 13 Nov 2026. Google can change these.
  • Google Apps Script triggers: simple trigger limits (no services that require authorization, 30 seconds) and installable triggers. Read 13 Nov 2026.
  • Google Apps Script UrlFetchApp.fetch reference: method, contentType, headers, payload, muteHttpExceptions. Read 13 Nov 2026.
  • SendFromChat REST API reference, getting started and templates: POST /messages, test and live keys, Idempotency-Key, errors, warm-up limits. Read 13 Nov 2026.
  • Meta's own pages decide template categories and charges. We did not retrieve them for this guide.

Do this from your AI assistant

SendFromChat connects Claude, ChatGPT, Cursor or any MCP client to the WhatsApp Business API — templates, bulk sends, inbox, chatbots and sequences, just by asking. 30 days free, no card.

Start free