I'm trying to execute the function by calling it from my Chrome Extension. I can see in my "My Executions" that the chrome extension called the function, but it's not pasting data into Google Sheets.
Function Call from Chrome Extension
post({ 'url': 'https://script.googleapis.com/v1/scripts/' + SCRIPT_ID + ':run',
'callback': executionAPIResponse,
'token': token,
'request': {
'function': 'setData',
'parameters': { 'data': JSON.parse(exec_data.value) },
}
});
Script Editor Code
function setData(parameters) {
try {
var doc = SpreadsheetApp.openById(DOC_ID);
var sheet = doc.getSheets()[0];
var data = parameters.data;
sheet.getRange(1, 1, data.length, data[0].length).setValues(data);
return {"status":"ok", 'doc':doc.getUrl()};
} catch(e){
// if error return this
Logger.log(e);
return {"status": JSON.stringify(e)};
}
}
I deployed the Apps Script project as "API Executable." I am wondering, is there something wrong with the way I deployed the app in Script Editor?
I found the mistake i was making. Actually the code was correct but while deploying as API Executable you have to always change the version to new one when you made changes to your code