📽️Google Sheets data into SprintHub
PreviousIntegrated Webhooks - Sending data from SprintHub to an external WebHook via automationNextIntegrated Webhooks - Calendly to SprintHub
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
function onEdit(e) {
var sheetName = 'Leads';
var sheet = e.source.getSheetByName(sheetName);
if (!sheet || e.range.getSheet().getName() !== sheetName) {
return;
}
// Checks if the edit is on the last row (assumes a new row is added manually)
var lastRow = sheet.getLastRow();
if (e.range.getRow() === lastRow) {
sendRowsToWebhook(sheet, lastRow, lastRow);
}
}
function sendRowsToWebhook(sheet, startRow, endRow) {
var url = 'https://sprinthub-api-master.sprinthub.app/api/hook/gxxxxxets?i=temxxxxp&access_token=ziqTxxxxxx0-X_';
for (var row = startRow; row <= endRow; row++) {
var rowValues = sheet.getRange(row, 1, 1, sheet.getLastColumn()).getValues()[0];
// Checks if required fields are filled
if (rowValues[0] === '' || rowValues[2] === '') {
Logger.log('Row ' + row + ' contains required empty cells.');
continue;
}
// Preparing data to send in the payload
var payload = {
'name': rowValues[0],
'lastName': rowValues[1],
'mobile': rowValues[2],
'email': rowValues[3]
};
Logger.log('Payload sent:', payload);
var options = {
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify(payload),
'muteHttpExceptions': true
};
try {
var response = UrlFetchApp.fetch(url, options);
Logger.log('Webhook response for row ' + row + ':', response.getContentText());
} catch (e) {
Logger.log('Error sending payload for row ' + row + ':', e.message);
}
// Wait 1 second before sending the next row
Utilities.sleep(1000);
}
}