Error while reading a .csv file and send it into google spreadsheet using kodular

Viewed 126

I want to read a csv file and send the data to a google spreadsheet. I am following the given link https://ai2.metricrat.co.uk/guides/export-csv-data-multiple-data-to-google-sheet

But I am getting the error as shown in the image. Error

My app script code is as follows

function doPost(e) {
  var data = JSON.parse(e.postData.contents) ; // or >> eval(e.postData.contents) ;
  var ss = SpreadsheetApp.getActive();
  var sh = ss.getSheetByName('Sheet1');
  for (var i=0;i<data.length;i++) {
    sh.appendRow(data[i]);
  }
  return ContentService.createTextOutput("Success") ;
}

My kodular blocks are shown in the image Kodular blocks

1 Answers

The line with JSON.parse(e.postData.contents) on google script got incorrect text to parse it.
In kodular, the list "global data" is something like ((11,12),(21,22)...).
To be valid JSON it has be like {[[11,12],[21,22]...]}.
So, you should replace all round brackets () with square brackets [], and add curly brackets to start and end.
Change 'global data' before you call 'Web1.Post Text' as shown:
[1]: https://i.stack.imgur.com/FCXV5.png

Related