Do you constantly look for easy ways to automate your work? Great, even I do. This is how I discovered: Google Sheets Webhooks integration. With this detail read you’ll be guided through:

  1. How to enable your Apps Script API with just 2 steps
  2. How to add a new container-bound Apps Script project to your Google Sheets
  3. How to update your script with open-source (pre-written) code and quickly deploy it as a web-app
  4. Authorise the newly added script through a custom menu and leverage it to receive & log the data

In this blog, you will learn about how Google Sheets Webhooks integration works, and what are some use cases for this Google Workspace app. You will also learn how a no-code platform can help you to quickly create a webhook and accept/log your incoming data to a Google Sheet, without needing any code or a new platform.

What is Webhooks for Sheets and How Does it Work?

Webhooks are background connections to a web server. They can be used to implement functionalities such as updating graph/numbers on their own or certain parts of a webpage updating themselves depending on an event and with the change in server-side values.

The “user-defined HTTP callbacks” are triggered by some events. That make an HTTP POST request to a webserver for latest updates. The webserver can be same or different from the original enclosing webpage. You can use webhooks for events on a third-party website depending on changes on a backend server. 

Simplify Google Sheets & Webhooks ETL & Data Integration using Hevo’s No-code Data Pipeline

Hevo is the only real-time ELT No-code Data Pipeline platform that cost-effectively automates data pipelines that are flexible to your needs. With integration with 150+ Data Sources (40+ free sources), we help you not only export data from sources & load data to the destinations but also transform & enrich your data, & make it analysis-ready.

Start for free now!

Get Started with Hevo for Free

Steps to Set up Google Sheets Webhooks Integration

Building up Google Sheets Webhooks Integration is a three step process that enables the users to send data from Google Sheets on any event change. Follow the steps given below to set up Google Sheets Webhooks Integration:

Download the Whitepaper on Automating Data Integration
Download the Whitepaper on Automating Data Integration
Download the Whitepaper on Automating Data Integration
Learn the key benefits of automating Data Integration

Step 1: Create and Configure a New Document

The first step involved in setting up Google Sheets Webhooks Integration requires you to create a new script. To build Google Sheets Webhooks Integration, you must first create a new document. Follow the steps given below to create and configure a Google Spreadsheet file:

  • Navigate to your Google Sheets account and select the option Blank to create a new Spreadsheet.
Google Sheets Webhooks - Blank Spreadsheet
Source: Self
  •  Populate the fields in your Spreadsheet.
Google Sheets Webhooks - Populating Fields
Image Source
  • Now, select the option Tools from the Toolbar menu and then click on Script Editor.
Google Sheets Webhooks - Script Editor
Image Source
  • Once you click on the Script Editor option, a new text editor will open up where you can insert any type of script of your own.
  • Paste the following piece of code in the Script Editor. It will just return rows 2-10 as JSON.
function doGet(e) {
var ss = SpreadsheetApp.getActive();
var rng = ss.getActiveSheet().getRange(2, 1, 10, 3)
var vals = rng.getValues()
Logger.log(vals)
return ContentService.createTextOutput(JSON.stringify(vals)).setMimeType(ContentService.MimeType.JSON);
}
function doPost(e) {
return HtmlService.createHtmlOutput(“post request received”);
}
  • Don’t forget to save the document once you have pasted the above code successfully. The final result will look something like the following:
Google Sheets Webhooks - Custom Script
Source: Self

Step 2: Publish Your Script

Once you have created the script, the second step in setting up Google Sheets Webhooks Integration requires you to deploy your script as a web app. Follow the steps to do so:

  • Click on the Publish button in the top bar and select the option Deploy as Web App to publish your script.
  • It is critical that you select “Anyone, even anonymous” in the “Who has access to the app” field on the newly appeared screen to make your data public. 
  • Now click on the Deploy button to publish the script.
  • Once you click on the Deploy button, a new pop-up window will appear which will provide you with the web app link.
Web App URL for Google Sheets Webhooks Integration
Image Source
  • This link will redirect you to a page that will contain all the JSON data fetched by your script.
Google Sheets Webhooks - JSON data
Image Source

Step 3: Create a Webhook

The final step involved in setting up Google Sheets Webhooks Integration requires you to create a new Webhook. There are numerous third-party tools available on the Internet that can be used to create a new Webhook or you can create a Custom Function in Google Sheets to leverage its functionalities to create a new Webhook. Follow the steps given below to create a new Webhook:

  • Navigate back to the Script Editor and paste the code given below to create your own custom function.
function currentTime() {
var d = new Date();
var currentTime = d.toLocaleTimeString()
return currentTime;
}
function CELL_CHANGED(row) {
var options = {
'method' : 'post',
'payload’ : JSON.stringify(row)
};

UrlFetchApp.fetch('http://requestbin.net/r/1hqonni1', options);
return "UpdatedAt: "+ currentTime()
}
  • This Custom Function will get triggered whenever there is a change in the input data.
  • You can now modify the sheet to include a call to the function that returns the entire row.
Google Sheets Webhooks - Return Message
Image Source
  • If you see a successful return message from the function, it means that the Webhook has been sent with the row data as an array. If you bake validation into your script, you can return a useful error message to the user, explaining why some of the input data is invalid, preventing bad data from ever reaching your Webhook.

Once you follow all the above instructions in the correct sequence, you will be able to set up Google Sheets Webhooks Integration in no time!

Use Cases of Google Sheets Webhooks

  1. To get real-time data from google sheets: When you want to incorporate any real time update in your google sheets data without the need to constantly poll for changes.
  2. To automate a task that needs gathering data from different sources: Webhooks helps you to connect Google Sheets and other multiple sources to a destination through its ‘hook’. This centralization of data will help you further for effective analysis.

Conclusion

This article provided you with a step-by-step guide on how to set up Google Sheets Webhooks Integration successfully. It also provides in-depth knowledge about the concepts behind every step to help you understand and implement them efficiently.  If you want to integrate data from various data sources such as Google Sheets into your desired Database/destination for free and seamlessly visualize it in a BI tool of your choice, Hevo Data is the right choice for you! It will help simplify the ETL and management process of both the data sources and destinations.

Visit our Website to Explore Hevo

Hevo Data provides its users with a simpler platform for integrating data from 150+ sources such as Google Sheets for Analysis. Hevo also allows integrating data from non-native sources using its in-built Webhooks Connector. It is a No-code Data Pipeline that can help you combine data from multiple sources. You can use it to transfer data from multiple data sources into your Data Warehouse, Database, or a destination of your choice. It also provides you with a consistent and reliable solution to manage data in real-time, ensuring that you always have Analysis-ready data in your desired destination.

Want to take Hevo for a spin? Sign Up for a 14-day free trial and experience the feature-rich Hevo suite first hand. You can also have a look at our unbeatable pricing that will help you choose the right plan for your business needs!

Share your experience of learning about Google Sheets Webhooks Integration! Tell us in the comments section below!

mm
Former Research Analyst, Hevo Data

Rakesh is a research analyst at Hevo Data with more than three years of experience in the field. He specializes in technologies, including API integration and machine learning. The combination of technical skills and a flair for writing brought him to the field of writing on highly complex topics. He has written numerous articles on a variety of data engineering topics, such as data integration, data analytics, and data management. He enjoys simplifying difficult subjects to help data practitioners with their doubts related to data engineering.

No-code Data Pipeline for Google Sheets