Natalie Kerby
Natalie Kerby

Reputation: 41

Getting 403 when trying to execute a google script

I am trying to execute a google script via API. I have authorized with all the necessary scopes and included my parameters, function, and dev mode:

POST https://script.googleapis.com/v1/scripts/{scriptId}:run

{
     "devMode":true,
     "function":"createNewSpreadsheetTrigger",
     "parameters":["{fileId}"]
}

But keep getting a 403:

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

I created this script with the same account that is trying to remotely execute.

Thoughts?

Thanks!

Upvotes: 4

Views: 4839

Answers (1)

Sourabh Choraria
Sourabh Choraria

Reputation: 2331

Per documentation -

The error 403, PERMISSION_DENIED: The caller does not have permission indicates that the Cloud Platform project used to authorize the request is not the same as the one used by the script.

I'd stumbled upon similar issues and so I'd created this article explaining the best course of action that suited my use-case.

However, here are the recommended steps -

  1. create a new google cloud platform project
  2. enable apps script api from gcp library
  3. create an oauth consent screen, against that project
  4. generate an api key
  5. type up a new script
    • update the manifest file with appropriate scopes
  6. change apps script's default project to the one newly created

Hope this helps.

Upvotes: 4

Related Questions