Actually… I got it to work partially.
I created a new sheet in the test spreadsheet called “settings”.
I created a table like this one:
Parameter |
Value |
a |
0 |
b |
123 |
c |
456 |
d |
789 |
and I added this piece of code at the end of “doPost” function that replaces the last three lines (result {“ok”:true}…)
var spreadsheetId = "<<Enter your spreadsheeet code here>>";
var rangeName = 'settings!A2:B5';
var values = Sheets.Spreadsheets.Values.get(spreadsheetId, rangeName).values;
if (!values) {
Logger.log('No data found.');
return ContentService.createTextOutput({"a":"0","b":"1","c":"2","d":"3"})
.setMimeType(ContentService.MimeType.JSON);
} else {
for (var row = 0; row < values.length; row++) {
Logger.log(' - %s, %s', values[row][0], values[row][1]);
}
var result = {
"a" : values[0][1],
"b" : values[1][1],
"c" : values[2][1],
"d" : values[3][1]
};
Logger.log(JSON.stringify(result));
return ContentService.createTextOutput(JSON.stringify(result)).setMimeType(ContentService.MimeType.JSON);
Now it also logs the content that was sent (in apps script control panel) and sends back the response to Particle API in JSON and that can be read back in the device using another great library by @rickkas7 :
Now I need to see how I can create some kind of form to interact with Apps Script…