Save WhatsApp messages and contacts to Google Sheets automatically
To save WhatsApp Business messages to Google Sheets automatically, send them as signed HTTP POSTs to an automation tool such as n8n, Make or Zapier, and let its Google Sheets step add a row per message: time, direction, phone number, name, text and message id. A second tab keyed on the phone number keeps one row per contact, updated when they write again.
easyCoexistence connects the WhatsApp Business number you keep in the app to Meta's Cloud API through Coexistence.
Forwarded deliveries are retried after about 1, 5, 30, 120, 360 and 1,440 minutes when your URL fails.
How long a forwarded POST waits for a 2xx answer before that delivery is retried.
Google Sheets API write requests allowed per minute per user per project; 300 per project.
Apps Script web app output is redirected to a one-time URL at script.googleusercontent.com.
Apps Script's doPost event object exposes the body and parameters, not the HTTP request headers.
Which route should fill the sheet?
Two routes exist on a number whose messages come through easyCoexistence, and they answer different needs. The Forward URL, set once per number, passes on Meta's original events whether or not an automation answers: customer messages, the replies your team types in the WhatsApp Business app and delivery statuses. It is the route for a full message log. A Call my webhook step inside an automation fires only for the messages that automation picks, and carries the recent chat, including the reply the automation just sent. It suits a sheet of leads, orders or requests that one automation handles. Both are signed, with different secrets.
| Forward URL (per number) | Call my webhook step (per automation) | |
|---|---|---|
| Fires on | Any message event on the number, with or without automations | Only messages that automation is picked for |
| Carries | Meta's original value: messages, phone replies, statuses | The message, the contact and up to 10 recent messages |
| Automated replies | Delivery statuses only, without the text | In history, direction out |
| Retries | 7 attempts over about 33 hours | One attempt |
| Signed with | The number's forward secret, shown once | The automation's Signing secret |
| Set in | Number page, Where incoming messages go card | The automation editor, or create_automation |
What fields arrive, and which columns should the sheet have?
A forwarded POST wraps one Meta change: id (the delivery), event (Meta's field name, such as messages or smb_message_echoes), received_at, connection (your number's id, phone and phone_number_id) and value, exactly as Meta sent it. In value, messages hold what customers wrote and message_echoes hold what your team typed on the phone. Phone numbers arrive as digits with the country code and no plus sign; store that column as plain text so Sheets does not turn it into a number. A user with a WhatsApp username may arrive with a business-scoped user ID beside the number, or instead of it, so keep a column for it.
How do you build the message log in n8n?
Three nodes. A Webhook node with HTTP Method POST, Respond set to Immediately, and its Production URL saved as the number's Forward URL. A Code node that checks X-EC-Signature with the forward secret and turns the event into rows, skipping delivery statuses. A Google Sheets node with the Append or Update Row operation, Column to match on set to Message id, so a retried delivery rewrites the same row instead of adding one.
The forward secret appears once, when you save the Forward URL; if it is lost, click New secret and paste the new one. n8n Cloud allows the crypto module in Code nodes; self-hosted n8n needs NODE_FUNCTION_ALLOW_BUILTIN=crypto.
const crypto = require('crypto');
const SECRET = 'whsec_...'; // the number's forward secret, shown once when you saved the Forward URL
const { headers, body } = $input.first().json;
const sig = /^t=(\d+),v1=([0-9a-f]{64})$/.exec(headers['x-ec-signature'] || '');
if (!sig || Math.abs(Date.now() / 1000 - Number(sig[1])) > 300) throw new Error('Bad or stale signature');
// n8n has parsed the body; it was sent as compact JSON, so JSON.stringify rebuilds the signed bytes.
const mac = crypto.createHmac('sha256', SECRET).update(sig[1] + '.' + JSON.stringify(body)).digest();
if (!crypto.timingSafeEqual(mac, Buffer.from(sig[2], 'hex'))) throw new Error('Bad signature');
const { event, connection, value } = body;
const names = Object.fromEntries((value.contacts || []).map((c) => [c.wa_id, c.profile?.name || '']));
const textOf = (m) => m.text?.body ?? m.button?.text ?? m.interactive?.button_reply?.title
?? m.interactive?.list_reply?.title ?? ('[' + m.type + '] ' + (m[m.type]?.caption || '')).trim();
const row = (m, direction, phone) => ({
time: new Date(Number(m.timestamp) * 1000).toISOString(), direction, phone,
user_id: m.from_user_id || '', name: names[phone] || '', text: textOf(m),
message_id: m.id, number: connection.phone,
});
let rows = [];
if (event === 'messages') rows = (value.messages || []).map((m) => row(m, 'in', m.from || '')); // statuses skipped
if (event === 'smb_message_echoes') rows = (value.message_echoes || []).map((m) => row(m, 'out', m.to || ''));
return rows.map((json) => ({ json }));How do you keep one row per contact?
Add a second Google Sheets node on a Contacts tab, also with Append or Update Row, matched on Phone. Map the phone, the profile name, the user ID, the time and the text of the latest message. The first message from a number creates its row; later ones update the name and the last-contact columns, so the tab doubles as a list of who wrote and when. Keep hand-written notes on a separate tab, looked up by phone, so the workflow never overwrites them.
The contacts saved in the phone's address book do not arrive this way. Meta sends them, with up to 6 months of chats, only to a direct webhook destination saved within 24 hours of connecting the number.
Can Apps Script receive the messages directly?
Not cleanly, so put a workflow tool in front of the sheet. Google serves an Apps Script web app's response through a redirect to a one-time script.googleusercontent.com URL, and easyCoexistence does not follow redirects. The 302 counts as a failed delivery: a forward is retried up to 7 times, and every retry runs doPost again and writes another row, while a Call my webhook step fails and emails you. doPost also cannot read request headers, so the X-EC-Signature check is impossible there.
Apps Script remains a good fit for the other direction, sending approved templates from rows of a sheet, which the Google Sheets integration page covers with code.
Can Make or Zapier fill the sheet instead?
Yes. In Make, start the scenario with Webhooks > Custom webhook and add Google Sheets > Add a Row; in Zapier, use Webhooks by Zapier with Catch Raw Hook, which keeps the headers, then Google Sheets > Create Spreadsheet Row. Both answer the POST at once with a 2xx, which is what a forward needs within its 10 seconds. Map the same fields as above from value.messages, and filter out events whose value carries statuses instead of messages.
Treat the hook URL as a password, since anyone holding it can post rows. Where your plan includes a code step, check X-EC-Signature there with the same HMAC recipe used in the n8n node.
How do you avoid duplicate or missing rows?
Duplicates come from retries. A forward that did not get a 2xx within 10 seconds is sent again with the same X-EC-Delivery header and the same id in the body, and the messages inside keep their wamid, so matching on Message id makes a retry harmless. On the webhook-step route, tests from Try it arrive with dry_run true: route them to a test tab or drop them.
Missing rows come from Google's write quota. The Sheets API allows 60 write requests per minute per user per project, and one n8n credential is one user; a burst of replies after a template campaign can exceed it and get HTTP 429. Turn on Retry On Fail in the Google Sheets node's settings, or collect messages for a few seconds and append them in one request.
How to set it up
- Check the number's modeOn the number's page, the card Where incoming messages go must show Through easyCoexistence. If it shows Straight to your system, choose Through easyCoexistence.
- Build the workflowWebhook node (POST, Respond Immediately), the Code node above, then Google Sheets with Append or Update Row matched on Message id. Activate it and copy the Production URL.
- Save the Forward URLPaste the Production URL into Forward URL (optional) and click Save forward URL. Copy the signing secret shown once into the Code node.
- Send a test messageFrom another phone, write to your number and reply to it from the WhatsApp Business app. Two rows should appear: one in, one out.
Common mistakes
- Checking a forward with an automation's Signing secret, or the reverse. The Forward URL is signed with the number's forward secret and Call my webhook with the automation's own; pick the secret by the X-EC-Event header.
- Appending a row per POST without a key. A delivery retried after a slow answer writes the same message twice; use Append or Update Row matched on the message id.
- Writing delivery statuses as messages. The messages event also carries sent, delivered and read statuses in value.statuses, which have no text and create empty rows.
- Saving an Apps Script web app URL as the Forward URL. Its redirect counts as a failure, so each of the 7 attempts runs doPost again and adds a duplicate row.
With automations on, a Forward URL passes Meta's original events to your workflow, signed with a secret only you hold and retried when your URL is down, and a Call my webhook step sends what an automation handled, with its reply. Both are included in the plan. US$ 9 down to US$ 0.75 per number per month, falling as you add numbers, with the first 3 days free.
easyCoexistence is a multichannel API and MCP server that connects AI agents such as Claude and ChatGPT to WhatsApp, Instagram, TikTok, Facebook and more. On WhatsApp it uses Coexistence: the business keeps using its number in the WhatsApp Business app while the AI works through Meta's official API.
Frequently asked questions
Does the sheet get the messages my team types on the phone?
Yes, through the Forward URL. Replies typed in the WhatsApp Business app arrive as smb_message_echoes events, with the customer's number in to. Replies sent by automations come back only as delivery statuses, so log their text from a Call my webhook step placed after the reply.
Can I load my existing chats into the sheet?
Not on a number whose messages come through easyCoexistence. Meta sends up to 6 months of one-to-one chats only to a direct webhook destination saved within 24 hours of connecting, once per connection. A number routed through easyCoexistence logs from the moment the Forward URL is saved.
Does easyCoexistence keep a copy of the messages?
Partly. On a number routed through easyCoexistence with automations on, message text is kept for the period you choose, 30, 90 or 365 days (90 by default), and shown in Conversations; forwarded deliveries are held up to 7 days for retries, and run logs 30 days. The sheet is your permanent copy.
Can my AI read the sheet to answer customers?
Not from a Reply with AI step, which reads only its Instructions and the chat. An AI agent can look things up through a custom HTTP tool, and a Call my webhook or Call an API step can send the question to a workflow that looks the answer up in the sheet and returns it as the reply.
Keep reading
Ready to get started?
Set up WhatsApp Coexistence in minutes, not months. The app keeps working on the phone.
Start Free TrialVerified on