I currently have a script that pushes data out to a webhook (to Integromat), whenever a cell is edited.
The end-goal is to get a JSON with key:value pairs, but so far I only managed to get my values out. But I can't properly re-use those inside Integromat. So I need to get the keys (column titles in row 1) mapped to it as well. But I'm stuck :')
This is my current code:
function onEdit(e){
const endColumn = 20; //<--- number of columns
const sheet = SpreadsheetApp.getActiveSheet();
var range = e.range;
var row = range.rowStart;
var range = sheet.getRange(row, 1, 1, endColumn);
var values = range.getValues()[0];
Logger.log(values)
var formData = {
'CELL_UPDATED': range.getA1Notation(),
'NEW_VALUE': range.getValue(),
'SHEET': sheet.getName(),
'CONTENT': JSON.stringify(values)
};
//console.log(formData);
var options = {
'method' : 'post',
'payload' : formData
};
UrlFetchApp.fetch('webhookurl', options);
}
What would the most efficient option be to add column headers to my JSON output?