Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my apps script deployed as API executable return Permission Denied?

I created a script in the script editor, published it as a "Deploy as API executable". Inside this script, I provided a doc_id to my sheet and defined a function to get data from that sheet.

I then went to https://developers.google.com/apps-script/execution/rest/v1/scripts/run to test the execution API. I added the scopes, authorized the app and tried it. I am getting the following error message:

"error": {
  "code": 403,
  "message": "The caller does not have permission",
  "status": "PERMISSION_DENIED"
}

Can someone tell me what I am doing wrong?

like image 218
Bellave Jayaram Avatar asked Oct 03 '15 08:10

Bellave Jayaram


People also ask

How do I enable apps in script API?

At the top of the console, click into the search bar and type part of the name of the API (for example, "Calendar"), then click the name once you see it. On the next screen, click Enable API. Close the API Console and return to the script editor. Click OK in the dialog.

How do I deploy a Google script to the web app?

Save a new version of the script by selecting File > Manage Versions, then Save New Version. Select Publish > Deploy as web app. Under Project version, select the version you just saved.


2 Answers

Even with everything okay, you can get that error by "devMode":true. Thanks to this, I wasted half a day when I tried to deploy for other users.

Just for the future reference.

like image 188
goodhyun Avatar answered Sep 19 '22 03:09

goodhyun


I did a mix of all of your suggestions, plus I needed to use the non 'obsolete' ID of the Project. When I publish the script, it gives me an ID, which I was using succesfully as long as owner runs the routine, and only within Google Chrome (If I try it on Edge it fails). When I publish and try it with a different user it stop working. I open the script, go to file / Project properties and copy the longer Script ID instead. The routine start working for any user then. In the following image I underscore in red the key that Works for developer alone, and in Green the key that Works for all users (they're cutted in purpouse, and my environment is in spanish so actual translated options may vary, sorry)

Project properties keys

I believe it is worth to make a summary:

  1. I follow intructions at 'Using the execution API' and quickstarts to publish my script as execution API. (Create the script, enable Google Apps Script Execution API, publish as API executable with Access by everybody)enter image description here
  2. I made the script visible fro everybody, on File / Sharing: API sharing settings
  3. I made sure that devMode was not set true on my call. Here the JavaScript call snipet: JavaScript call snippet
  4. I made sure that all of the scopes in the Project were included during the OAuth request: API scopes API OAuth call
  5. I have to wait a few minutes to get all security rights to get ready (i.e. OAuth credentials)

Basically, these are all the required steps I needed to follow in order to get the script up and running. Hope it helps. Finally I would like you to see what I saw when it failed and when it succeeded:API call fail API call success

Thank you!

like image 35
Chesare Avatar answered Sep 22 '22 03:09

Chesare