
Unleashing Apps Script Webhooks: Connect Any App to Google Sheets
Hey everyone! Welcome back to MageSheet.
We've talked about how to completely overhaul your internal workflows by using Apps Script to build custom HTML interfaces and secure B2B client portals.
But what if you don't even want a user interface? What if you want your Magento store, your HubSpot CRM, or a custom mobile app to push data directly into your Google Sheets silently in the background?
To do this, we need to turn our Google Workspace environment into an API. And in Apps Script, that's done by building Webhooks.
What is a Webhook?
Think of an API as you walking up to a database and asking, "Hey, do you have any new orders?" (Polling). A Webhook, on the other hand, is the database saying, "Here's my phone number. Call me the millisecond a new order arrives."
Setting up a webhook listener in Google Apps Script is arguably the fastest, cheapest, and most reliable way to ingest live data from thousands of enterprise platforms like Magento, Shopify, Zapier, or Stripe without paying for third-party middleware like Make.com or Zapier.
Enter doPost() and doGet()
Apps Script has two magical, reserved functions that listen for incoming HTTP traffic:
doGet(e): Listens for incoming HTTP GET requests (usually data appended to a URL, like?name=yusuf).doPost(e): Listens for incoming HTTP POST requests (usually a hidden payload of JSON data).
If you define these functions and publish your script as a Web App, Google gives you a unique URL. Anytime an external system sends data to that URL, the corresponding function executes automatically!
Step 1: Writing the Webhook Listener
Let's say we have a Magento store and we want to push the customer's email and order total into a Google Sheet every time a successful checkout occurs.
Open Extensions > Apps Script in your blank Google Sheet and write this code:
// Code.gs
// The external system will send a JSON payload via HTTP POST
function doPost(e) {
try {
// 1. Parse the incoming JSON payload from the request body
// e.postData.contents holds the raw JSON string sent by the webhook
const payloadStr = e.postData.contents;
const orderData = JSON.parse(payloadStr);
// 2. Select the spreadsheet
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Orders");
// 3. Prepare the row data
const timestamp = new Date();
const customerEmail = orderData.email || "No Email provided";
const orderTotal = orderData.total || 0.00;
const orderId = orderData.order_id || "Unknown";
// 4. Quickly append to the sheet
sheet.appendRow([timestamp, orderId, customerEmail, orderTotal]);
// 5. Always return a 200 OK response so the sending app knows it succeeded
return ContentService.createTextOutput(JSON.stringify({
"status": "success",
"message": "Order appended!"
})).setMimeType(ContentService.MimeType.JSON);
} catch (error) {
// Handle failures gracefully
return ContentService.createTextOutput(JSON.stringify({
"status": "error",
"message": error.toString()
})).setMimeType(ContentService.MimeType.JSON);
}
}
Step 2: Deploying the Webhook
Code alone isn't enough. We need the physical URL.
- Click Deploy > New deployment.
- Select type: Web app.
- Execute as: Me (Crucial!).
- Who has access: Anyone (So Magento, which is unauthenticated to Google, can reach it).
- Click Deploy.
You will receive a URL that looks like this:
https://script.google.com/macros/s/AKfycby..._aBCD/exec
Copy this URL. This is your secure Webhook Endpoint.
Step 3: Sending Data (Testing)
You don't even need Magento to test this. You can use a tool like Postman, or a simple curl command in your terminal to fire data at your new Google Sheet API.
curl -X POST "https://script.google.com/macros/s/AKfycby..._aBCD/exec" \
-H "Content-Type: application/json" \
-d '{"email": "boss@company.com", "total": 450.00, "order_id": "MAG-9912"}'
If you look back at your Google Sheet, the data will instantly appear!
The Resulting Table in Sheets
| Timestamp | OrderID | Total | |
|---|---|---|---|
| 10/27/2026 14:32:01 | MAG-9912 | boss@company.com | $450.00 |
Why This Will Change Your Architecture
Once you master doPost(), you unlock real-time digital architecture that costs exactly $0 in server fees.
- Form submissions from Webflow or WordPress? Push them directly to Sheets.
- Stripe payment succeeded? Log it via a webhook.
- Custom internal mobile app? Make it completely Serverless connected straight to Google Workspace.
By bypassing rigid, slow middleware options and coding direct webhooks in Apps Script, you own your logic stream completely.
If you have a massive e-commerce operation running on Magento, and need enterprise-grade, bi-directional syncing between Magento and Google Workspace without the monthly overhead of SaaS integrators, check out our consulting solutions!


