4

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!

TheMaster
  • 45,448
  • 6
  • 62
  • 85
Natalie Kerby
  • 41
  • 1
  • 2
  • Can you share you code for granting Auth for the Google Script? You can also check [Authorization for Google Services](https://developers.google.com/apps-script/guides/services/authorization#granting_access_rights) – Mr.Rebot Jun 04 '16 at 14:31

1 Answers1

4

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.

Sourabh Choraria
  • 2,255
  • 25
  • 64