Hello, I am trying to import my old data from google sheets into ubidots. I am following this article. https://help.ubidots.com/developer-guides/import-data-to-ubidots-from-google-sheets
But when I run the script I get the error, TypeError: Cannot call method “getDataRange” of null
Following is the part of the script.
function onOpen() {
var sheet = SpreadsheetApp.getActive();
var menuItems = [
{name: 'Send Data', functionName: 'sendData'}
];
sheet.addMenu('Ubidots', menuItems);
}
function sendData() {
var sheetApp = SpreadsheetApp.getActive();
var sheet = sheetApp.getSheetByName("Data");
var data = sheet.getDataRange().getValues();
var payload = {};
for (var i = 1; i < data.length; i++) {
var date = new Date(data[i][0]);
var timestamp = date.getTime();
for (var j = 1; j < data[0].length - 1; j++){
payload[data[0][j]] = {"value": data[i][j], "timestamp":
timestamp};
}
var status = send_to_ubidots(DEVICE_LABEL, payload);
if (status == null){
sheet.activate().getDataRange().getCell(i +
1,6).setValue("Couldn't send data");
}
else{
sheet.activate().getDataRange().getCell(i +
1,6).setValue("Sent");
}
}
}
I read the forums and I see many of us are getting this error I tried a few things that was mentioned in the forums like…but didnt work!
var ss = SpreadsheetApp.openById(“Your Sheet ID here”);
var sheet = ss.getSheetByName(“Name of your Sheet”);
. Was anyone able to solve this issue?
Thank you