I have this Google Apps Script bound to a sheet and published as a web app which is acting as a webhook to collect data. This works well and collects the first two results in the script (Insert the data into the sheet) just fine. Time and the complete data package into columns 1 and 3 respectively.
function doPost(e) {
var jsonString = e.postData.getDataAsString();
var event = JSON.parse(jsonString)
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Data");
var timeStamp = new Date();
var time = Utilities.formatDate(timeStamp, "BST", "dd/MM/yyyy, h:mm a");
var lastRow = sheet.getLastRow();
//Insert the data into the sheet
sheet.getRange(lastRow + 1, 1).setValue(time);
sheet.getRange(lastRow + 1, 3).setValue(event["data"]);
sheet.getRange(lastRow + 1, 6).setValue(data.reference);
}
The information that is retrieved from the webhook in column 3 is in this format once parsed but I'm struggling to Search for an element in this parsed JSON string array using google apps script and was hoping someone can point me in the right direction.
{processing={acquirer_reference_number=24022122407531018095, acquirer_transaction_id=57631018089}, id=pay_n4m745lnx7uy2tmgx4z26mksi, action_id=act_qqno6t6jctdkzbuk2fu3js71e, response_summary=Approved, metadata={is_supplementary=True, ps_id=9, token=tok_war7hee5nole7d21bknt45dm, transaction=7125, hash=84c478fdfbdb2515d46542adbd6ggd516dc0048fd67, order_id=83245142, sandbox=0}, amount=271.0, processed_on=2022-09-21T13:35:32Z, response_code=10000, currency=USD, reference=2694931}
I'd really like to search for these three elements within the data and return them into columns 4, 5 and 6 respectively. The order in which these appear seems to be random, so I cannot rely on an index:
- amount=271.0
- reference=2694931
- is_supplementary=True
You can see I've attempted to use dot notation and I've also tried bracket notation but to no avail.
Thanks for reading.
