Articles on: Integrations

How to INTEGRATE VIA WEBHOOK with Google Sheets

IMPORTANT: Google is limiting some features within basic Google accounts. To integrate with Google Sheets, you need a GSuite account.


  1. Go to the Google Sheets home page and create a new blank spreadsheet:



  1. On the first tab, enter the names of each field that will be filled in on your landing page form, one per column (as in the example below):



  1. After that, go to the "Tools > Script Editor" menu (or "Ferramentas > Editor de Script", if your language is set to Portuguese).



  1. Once you access the scripts area, you will see a screen like the image below. There, give your project a name where it says "Untitled project". You can call it "API GreatPages".



  1. Next, select all the content and replace it with the code below:


// Link de compartilhamento do Google Sheets
var SPREADSHEET_URL = 'https://docs.google.com/spreadsheets/';

function doPost(e) {
var values = getValues(e);

if (SPREADSHEET_URL) {
handleSpreadsheet(values, SPREADSHEET_URL);
}

return ContentService.createTextOutput('OK');
}

function getValues(e) {
var values = JSON.parse(e.postData.contents);
var answers = values["answers"];
if (typeof answers === "object") {
Object.keys(answers)
.forEach(function(answerLabel) {
var answer = answers[answerLabel];
values[answerLabel] = answer != null ? answer.toString() : answer;
});
delete values["answers"];
}
values['received_at'] = new Date();
return values;
}

function handleSpreadsheet(values, spreadsheetUrl) {
var ss = SpreadsheetApp.openByUrl(spreadsheetUrl);
var sheet = ss.getSheets()[0];
var headerMap = getExistingKeyColMap(sheet);
updateKeyColMap(sheet, headerMap, values);
writeValuesWithHeaderMap(sheet, headerMap, values);
}


function getExistingKeyColMap(sheet) {
var map = {};
sheet.getRange('1:1').getValues()[0].forEach(function(value, colIndex){
if (value.trim().length) {
map[value] = colIndex + 1;
}
});
return map;
}


function updateKeyColMap(sheet, headerMap, values) {
var maxColIndex = 0;
Object.keys(headerMap).forEach(function(key) {
maxColIndex = Math.max(maxColIndex, headerMap[key]);
});

Object.keys(values).forEach(function(valueKey) {
if (headerMap[valueKey] !== undefined) {
return;
}

// The values object has a key we haven't seen before.
maxColIndex += 1;
sheet.getRange(1, maxColIndex).setValue(valueKey);
headerMap[valueKey] = maxColIndex;
});
sheet.setFrozenRows(1);

var headerRow = sheet.getRange("1:1");
headerRow.setFontWeight("bold");
}

function writeValuesWithHeaderMap(sheet, headerMap, values) {
const rowIndex = sheet.getLastRow() + 1;
Object.keys(values).forEach(function(key) {
const colIndex = headerMap[key];
sheet.getRange(rowIndex, colIndex).setValue(values[key]);
});
}

function test() {
doPost({
postData: {
type: "application/json",
contents: '{ "hello": "world" }',
}
})
}


1- On the second line, where you see -> https://docs.google.com/spreadsheets, replace it with the link to your Google spreadsheet;


The link to your Google spreadsheet must be open for access (public);


  1. Save the script by clicking the "Save" icon;



  1. After that, click "Deploy" and, in the menu that opens, click "New deployment";




  1. On the next screen that opens, click the gear icon and then click "Web app";




  1. After that, a space will open on the screen where you will need to add a description for the integration, select your Gmail account and, finally, select the "Anyone" option, as in the example below;



  1. After clicking "Deploy", the "Authorize access" button will appear on the next screen, and that is where you should click;



  1. Next, you will be asked about some permissions. Choose a Google account and follow the process;
  2. Once the permissions are complete, the integration URL will be generated. Copy it and save it so you can implement it in GreatPages;



  1. Log in to GreatPages and open the form settings (click on the form and then click "Editar");



  1. Go to "Configurar", and in the Integration section click "Adicionar integração";



  1. Select the “Webhook” option;



  1. On the next screen you will need to paste the link generated in Google Sheets into “URL da integração”, and select the “POST+JSON” option. Finally, move on by clicking “Continuar” (there is no need to fill in the “token” field).



  1. On the “Configurar campos” screen you will need to set up the field variables. They must be exactly the same as the variables you set up in the spreadsheet.


Finally, click Salvar! Your integration is ready.


Still have questions? Reach out to our team on Chat! We're always happy to help.

Updated on: 08/01/2026

Was this article helpful?

Share your feedback

Cancel

Thank you!