Workflow
1.Create Google apps project.
2.Create files at project.
→env.gs&code.gs
3.Copy the code below
Put spreadsheet id & sheet name at the appropriate place.
env.gs
const SPREAD_SHEET = SpreadsheetApp.openById('spreadsheet id');
const SHEET_API = "sheet name";
code.gs
function getData(sheetName) {
var sheet = SPREAD_SHEET.getSheetByName(SHEET_API);
const rows = sheet.getDataRange().getValues();
const keys = rows.splice(0, 1)[0];
return rows.map(row => {
const obj = {};
row.map((item, index) => {
obj[String(keys[index])] = String(item);
});
return obj;
});
}
function doGet() {
var data = getData('SHEET_API');
return ContentService.createTextOutput(JSON.stringify(data, null, 2))
.setMimeType(ContentService.MimeType.JSON);
}
4.Push Deploy
Then select New Deploy
Change "Users who can access" to "Everyone"
5.Get url