Skip to main content

Google Sheets webhook tutorial

To connect a webhook to Google Sheets, open Extensions then Apps Script, add a script that calls UrlFetchApp.fetch() to send data or handles doPost() to receive it, and deploy the script as a Web App. That gives you a working webhook endpoint without hosting your own server.

We'll cover both sending and receiving. If you only need one, skip ahead to the sending tutorial or the receiving tutorial. For a refresher first, see what a webhook is.

Building webhooks?
Svix is the enterprise ready webhooks sending service. With Svix, you can build a secure, reliable, and scalable webhook platform in minutes. Looking to send webhooks? Give it a try!

Google Sheets webhook sender

Building a Google Sheets webhook sender is a three step process that lets you send data from Google Sheets when content in your sheet changes.

Step 1: Create your sheet and add a script

We’re going to start with a new spreadsheet and add some column headings but you can also configure an existing document.

Select Extensions from the Toolbar menu and then select Apps Script.

Apps Script

A text editor should open up. Delete the code and insert the following code:

function doGet(event) {
var spreadsheet = SpreadsheetApp.getActive();
var lastRow = Math.max(spreadsheet.getLastRow(),1);
var range = spreadsheet.getActiveSheet().getRange(2, 1, lastRow-1, 3);
var values = range.getValues();
Logger.log(values);

return ContentService.createTextOutput(JSON.stringify(values));
}

function doPost(event) {
return HtmlService.createHtmlOutput('request received');
}

function currentTime() {
var d = new Date();
var currentTime = d.toLocaleTimeString();

return currentTime;
}

function ROW_CHANGED(row) {
var options = {
'method' : 'post',
'payload' : JSON.stringify(row)
};

UrlFetchApp.fetch('ENTER YOUR WEBHOOK ENDPOINT URL HERE', options);

return "UpdatedAt: "+ currentTime()
}

The doGet function will trigger when you receive a GET request and return the current values in the spread sheet. Similarly, doPost triggers when you receive a POST request. ROW_CHANGED is the custom function you'll use in your spreadsheet to track the changes for a specific row.

Make sure to save your changes after you’ve entered the script.

Step 2: Get your webhook URL endpoint and publish your script

If you already have your endpoint URL, just enter it into the code above.

We're going to use Svix Play.

Svix Play

Once you enter the script, you need to deploy your script as a web app:

Click on the Deploy button in the top right and select New Deployment.

Click on Select type and choose Web app.

You can add a description if you want.

Under Web app choose to execute as yourself and authenticate.

Under Who has access choose Anyone.

Click Deploy.

Step 3: Test your Google Sheets webhook integration

We can see that when we add data to the spreadsheet, our receiver catches the webhook message:

Adding a row of data in the Google Sheets sender Svix Play showing the received webhook payload

Here is a link to the final sheet if you want to make a copy (Don't forget to replace the endpoint URL with your own!

Google Sheets webhook receiver

If we want to receive webhooks with our Google Sheet webhook integration, there are also 3 steps:

Step 1: Create your sheet and add the script

We’re going to start with a new spreadsheet and enter some column headers but you can also configure an existing document.

Select Extensions from the Toolbar menu and then select Apps Script.

Apps Script

A text editor should open up where you can insert the following code:

function doGet(e) {
return HtmlService.createHtmlOutput("request received");
}

function doPost(e) {
var params = JSON.stringify(e.postData.contents)
params = JSON.parse(params)
var body = JSON.parse(e.postData.contents)
var amount = body.amount
var eventType = body.eventType
var sheet = SpreadsheetApp.getActiveSheet();
var lastRow = Math.max(sheet.getLastRow(),1);
sheet.insertRowAfter(lastRow);
var timestamp = new Date();
sheet.getRange(lastRow + 1, 1).setValue(timestamp);
sheet.getRange(lastRow + 1, 2).setValue(eventType);
sheet.getRange(lastRow + 1, 3).setValue(amount);
SpreadsheetApp.flush();

return ContentService.createTextOutput(JSON.stringify(body))
}

Make sure to save your changes after you’ve entered the script. The doGet function is triggered when you receive a GET request while the doPost function is triggered when you receive a POST request. This code is specific to our example. To customize it for your sheet, you would change the variables to reflect the data in the body of your request.

Step 2: Publish your script

Once you have entered your script, you need to deploy your script as a web app. Follow the steps to do so:

Click on the Deploy button in the top right and select New Deployment.

Click on Select type and choose Web app.

You can add a description if you want.

Under Web app choose to execute as yourself and authenticate.

Under Who has access choose Anyone.

Click Deploy.

Copy the Web app URL (You will need this!).

Step 3: Test your script

Once you’ve published your script, you should test it to make sure its working. You’ll need to send a POST request to the Web app URL you copied at the end of Step 2. We'll use Postman. Just make sure you set the request to POST and the data type of the body to JSON.

Sending a test POST request to the Web App URL in Postman

If its working correctly, you should see new rows of data in your sheet when you send the request.

New rows appearing in the Google Sheet after receiving a webhook

Here is a link to the final sheet if you want to make a copy.

When to move beyond Google Sheets

Apps Script is a quick way to send or receive webhooks from Google Sheets without hosting a server. It also has limits: no signature verification, no automatic retries when a delivery fails, and Google's quotas on how often a script can run. When you need to send webhooks reliably at scale, with retries and verification built in, Svix handles that for you.