Google Sheets allow users to create, edit, and collaborate on spreadsheets online. The following example demonstrates how to set up a custom webhook for a Google Sheets spreadsheet.
Prerequisites
Google account
Google Drive
Obtain the Webhook URL
Log in to Google and create a Google Sheets spreadsheet.
Name the file.
In menu bar, select Extensions > App Script.
Create the following function inside the Google App Script. This function allows you to send items and creates the headers automatically based on the key properties from the body posted.
Note: Be sure to name the function doPost.function doPost(e) {
var data = JSON.parse(e.postData.contents);
var sheet = SpreadsheetApp.openById(
'<Google Sheet ID>'
).getActiveSheet();
var newHeaders = Object.keys(data);
var lastColumn = sheet.getLastColumn();
var existingHeaders = [];
if
(lastColumn >
0
) {
existingHeaders = sheet.getRange(
1
,
1
,
1
, lastColumn).getValues()[
0
];
}
if
(existingHeaders.length ===
0
|| !arraysEqual(existingHeaders, newHeaders)) {
sheet.getRange(
1
,
1
,
1
, newHeaders.length).setValues([newHeaders]);
}
var rowData = [];
for
(var key in data) {
if
(data.hasOwnProperty(key)) {
rowData.push(data[key]);
}
}
sheet.appendRow(rowData);
return
ContentService.createTextOutput(JSON.stringify({ result:
'success'
}))
.setMimeType(ContentService.MimeType.JSON);
}
function arraysEqual(arr1, arr2) {
if
(arr1.length !== arr2.length)
return
false
;
for
(var i =
0
; i < arr1.length; i++) {
if
(arr1[i] !== arr2[i])
return
false
;
}
return
true
;
}
Change the value of openByid('<Google Sheet ID>'). The Google Sheet ID is located in your file URL.
Example:SpreadsheetApp.openById('1mb5H7pUr1IKUSF91uR5TlBE34RrENbIgQgtfoG7rrI8').getActiveSheet();
Select Deploy > New Deployment.
For the type, select Web app.
Enter a description.
For Execute as, enter your gmail account
For Who has access, select Anyone. Anyone with the URL will be able to use the webhook function.
Select Deploy.
Authorize access to the data.
Select your Google account to continue. If needed, allow access to your Google account.
Once this is done, the deployment will be updated and the web app URL will be available.
Copy the URL that was automatically generated to test it in Elements.
Test the Webhook in Elements
Sign in to Elements and create an automation.
Action type: Execute Custom Webhook
Webhook URL: Enter the URL obtained in the previous example.
HTTP method: POST
Content type: JSON (application/json)
Request body:
{
"column1"
:
"hello"
,
"column2"
:
"world"
}
Execute the action through the dashboard.
View the spreadsheet and verify that information was written to the file.
Postman Test
Postman may be used to create a new POST request using the web app URL from the Google app scripts.
© 2025 Honeywell International Inc. All Rights Reserved.