1

I have a small Google Apps Script that I have deployed as API executable. Although I have made the call with a valid token for the scope I'm using (spreadsheets), I can't get past this 403 PERMISSION_DENIED error. I'm now testing this on the API's Explorer with the same error.

Does anyone have any ideas of what I might be missing?

My script is simple (still incomplete, but it runs - which should be enough for these initial tests):

OAuth Scope required by script (copied from API's Explorer):
https://www.googleapis.com/auth/spreadsheets

function myFunction(get) {
  var ss = SpreadsheetApp.openById("1axDlnPaoEwhlb_Vs5SLBvkGJrR-fSeOLuHEdSBXCTBg"); // I'm not getting anything from the sheet at this point, I included it just to make sure that the script requires the spreadsheets scope

  get += " " + "success!";

  return  ContentService.createTextOutput(get);
}

The request (copied from API's Explorer):

POST https://script.googleapis.com/v1/scripts/1d1EKj7vi-gzC0gB02qjw_qBPE1zSrZtJp-YUWuKm3NL3-3t6Sixpm0TZ:run?key={YOUR_API_KEY}

{
 "function": "myFunction",
 "parameters": [
 "Hello world!"
 ]
}

The response (copied from API's Explorer):

{
    "error": {
        "code": 403,
        "message": "The caller does not have permission",
        "status": "PERMISSION_DENIED"
    }
}
TCN
  • 1,571
  • 1
  • 26
  • 46

2 Answers2

2

You may want to check these 3 things:

  • Make sure that your app script is associated with the correct Dev Console Project.
  • Enable Apps Script Execution API.
  • If you're running a function in an Apps Script using Method: scripts.run, set devMode: true if you're the owner of the script. Otherwise, use the default value which is false.

Also, you should meet the listed requirements in Using the Execution API.

See this related SO post for additional insights.

Community
  • 1
  • 1
Teyam
  • 7,686
  • 3
  • 15
  • 22
  • The issue was the first point: my script was associated with the wrong console project. – TCN May 21 '17 at 08:41
1

The script should be associated with the developer console project id that corresponds with OAuth 2.0 client ID used (On the script editor of your current script: Resources > Cloud Platform Project, then enter your project id number) This was the reason why my script wasn't working (yours may differ, see Teyam's answer which I've marked as the correct one).

Community
  • 1
  • 1
TCN
  • 1,571
  • 1
  • 26
  • 46