Home > Net >  doPost not running for other users in google appscript
doPost not running for other users in google appscript

Time:06-25

I have deployed my appscript as a form addon and as a web app both. Everything seems to be working fine in the container form. But now I'm facing this issue where doPost function is not running as I have to run the function as other user. I tried this code from this enter image description here

I'm getting this error enter image description here

I've been stuck for 3 days any help is appreciated Thank you

UPDATED QUESTION:

APPSCRIPT DOPOST

function doPost(e) {
 var data = JSON.stringify(e);
 var jsonData = JSON.parse(data);
 let query = jsonData.queryString;
 let params = query.split("&");

 let destinationId = params[0].split("=")[1];

 // code is breaking here saying "you don't have access to the document"
 let ss = SpreadsheetApp.openById(destinationId);

 let sheetName = ss.getActiveSheet().getSheetName();
 let dataSheet = ss.getSheetByName(sheetName);

 var uniqueIdCol = dataSheet.getRange("A1:A").getValues();
 let rowToUpdate;
 // code to update row...
}

BACKEND CODE

// call appscript to update status sheet
  const data = {
    comment
  };
  let scriptId = process.env.DEPLOYMENT_SCRIPT_ID;
  const config = {
    method: "post",
    url: `https://script.google.com/macros/s/${scriptId}/exec?destinationId=${destinationId}&uniqueId=${uniqueId}&status=${status}`,
    data,
    headers: {
      Authorization: `Bearer ${respondent.form.oAuthToken}`,
    },
  };

  await axios(config);

These are the scopes which I requested to user

"https://www.googleapis.com/auth/script.container.ui",
"https://www.googleapis.com/auth/forms.currentonly",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/spreadsheets",
"https://www.googleapis.com/auth/script.send_mail",
"https://www.googleapis.com/auth/forms",
"https://www.googleapis.com/auth/script.scriptapp",
"https://www.googleapis.com/auth/drive"

UPDATED QUESTION 2

I had made a script which can write to google sheet with some extra data which I send from my node backend.

So my script has doPost function which is invoked from backend. I send destinationId of the sheet to know in which sheet to write as in the code above.

I have deployed the webapp as Execute as: Me and Who has access to the app: Anyone.

I'm able to run the doPost function but not able to write to sheet.

Hope my question is clear

CodePudding user response:

So after struggling for 4 days I was able to send email and write to spreadsheet with users OAuth token by directly interacting with Sheets API and Gmail API instead of doing it through ScriptApp doPost method

  • Related