Sync all RealtimeDB data to the Google's sheet columns
For every time im adding, or editing a product through my app, I am trying to write Firebase RealtimeDB data into a Google Sheets spreadsheet through Google Appscript.
This is what my RealtimeDB looks like
And this is my goal for every product (ignore the blue box)
This is what i have done so far but i do not know how to handle the sheet ranges and add the data in those specific positions.
url="https://inventory-c1e.firebaseio.com/Items.json?&auh=pur6Ka8wYVAd" xpath="OMCPC150C/itembarcode" //here im trying something but dont know how to continue for all DB values function addProduct() { var sheet = SpreadsheetApp.getActiveSheet(); sheet.appendRow([IMPORTJSON()]); } function IMPORTJSON(){ try{ var res = UrlFetchApp.fetch(url); var content = res.getContentText(); var json = JSON.parse(content); var patharray = xpath.split("/"); //Logger.log(patharray); for(var i=0;i<patharray.length;i++){ json = json[patharray[i]]; } //Logger.log(typeof(json)); if(typeof(json) === "undefined"){ return "Node Not Available"; } else if(typeof(json) === "object"){ var tempArr = []; for(var obj in json){ tempArr.push([obj,json[obj]]); } return tempArr; } else if(typeof(json) !== "object") { return json; } } catch(err){ return "Error getting data"; } }
So please kindly guide me on how to continue