I am trying to execute a simple Apps script to retrieve data from my google sheet. However, I get the error:
Bad value (line 2, file "Code", project "Untitled project")
when I paste the link:https://script.google.com/macros/s/AKfycbw8_1qGhuEMvfOEbLAx69x4fXyPl4sKQc4dvka81i5t42MkZpU/exec (the link provided for my web app after publishing) into my browser and hit enter.
However,when I click "test web app for your latest code" after publishing, it displays the JSON correctly without any issues. My app script code is as follows:
function doGet() {
var ss = SpreadsheetApp.openById('1gQKvGO0fhcrgqeke8HkUqm5Mb9dXWbaflIDmIo-pWcA');
var sheet = ss.getSheets()[0];
// Get the range of cells that store employee data.
var employeeDataRange = ss.getRangeByName("Range1");
// For every row of employee data, generate an employee object.
var employeeObjects = getRowsData(sheet, employeeDataRange);
return ContentService.createTextOutput(JSON.stringify(employeeObjects)).setMimeType(ContentService.MimeType.JSON);
}
Other posts mention that the spreadsheet id must be correct but I am pretty sure my id is correct.
From your question, it seems that you have changed the code but you have not republished it with latest version, so when you "test web app for your latest code", it works fine but when you use your publishing link, it crashes.
go to : publish > deploy as webapp > select project version to new and update the project.