Scopes required for `clasp run`

1,813 views
Skip to first unread message

John Smith

unread,
Mar 30, 2022, 11:07:40 AM3/30/22
to Google Apps Script Community
Hi, 
I'm trying to use `clasp run abc` to run a GAS function from the command line. I've created a completely new project with only one file `Code.js` with one function in it:
```
function abc() {
  return "def"
}
```
Note that I'm already globally logged in to push/pull using clasp. 
I've cloned the new project and am trying to run my function using `clasp run abc`, and getting a message telling me that I'm not authenticated for the scopes required by the script. However, when I check the properties of my project, the list of OAuth scopes is empty, so I have no idea what's missing to run this simplistic function. 

Can anyone point me in the right direction? 
Thanks! 

David

Clark Lind

unread,
Mar 30, 2022, 12:31:09 PM3/30/22
to Google Apps Script Community
Try following these instructions. Looks like you have to edit the  appsscript.json file to add: 

"executionApi": { 
  "access": "ANYONE" 

John Smith

unread,
Apr 1, 2022, 10:39:52 AM4/1/22
to Google Apps Script Community
Thanks Clark. 
I've tried adding these lines to appsscript.json but am still getting the same message. I've also tried running simple `clasp run`, I'm presented with a list of functions (well only `abc` in my case), but when I select it it's still the same. 

As I said, I have copied my ~/.clasprc.json file into the current directory (where I have the .clasp.json file), maybe it should be a different authentication file? 

Below is a dump of the commands I've tried. 

Thanks again! 

David

$ cat .clasp.json
{"scriptId":"1xDYPMP71VtnmfG7C186ZN7XetUE1-qxRy3zPDzq1nupoYaaI8HwU0c7r","rootDir":"."}
$ clasp run
Running in dev mode.
? Select a functionName abc
Hey! It looks like you aren't authenticated for the scopes required by this script.
Please enter the scopes by doing the following:
1. Open Your Script: https://script.google.com/d/1xDYPMP71VtnmfG7C186ZN7XetUE1-qxRy3zPDzq1nupoYaaI8HwU0c7r/edit
2. File > Project Properties > Scopes
3. Copy/Paste the list of scopes here:
            ~ Example ~
https://mail.google.com/
https://www.googleapis.com/auth/presentations
----(When you're done, press <Enter> 2x)----
 
Added 0 scopes to your appsscript.json' oauthScopes
Please `clasp login --creds <file>` to log in with these new scopes.
$ cat appsscript.json
{
  "timeZone": "America/New_York",
  "dependencies": {},
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "executionApi": {
    "access": "ANYONE"
  },
  "oauthScopes": [
    "openid",
    "https://www.googleapis.com/auth/userinfo.profile",
    "https://www.googleapis.com/auth/cloud-platform",
    "https://www.googleapis.com/auth/script.projects",
    "https://www.googleapis.com/auth/script.webapp.deploy",
    "https://www.googleapis.com/auth/logging.read",
    "https://www.googleapis.com/auth/drive.metadata.readonly",
    "https://www.googleapis.com/auth/userinfo.email",
    "https://www.googleapis.com/auth/service.management",
    "https://www.googleapis.com/auth/drive.file",
    "https://www.googleapis.com/auth/script.deployments",
    "https://mail.google.com/",
    "https://www.googleapis.com/auth/presentations",
    "https://www.googleapis.com/auth/spreadsheets"
  ]
}

Clark Lind

unread,
Apr 1, 2022, 12:52:15 PM4/1/22
to Google Apps Script Community
Do you have a credentials file (creds.json)? It looks like you still aren't authenticated/logged in properly. 

To use clasp run, you need to complete 4 steps:

1. Set up a Project ID.
2. Create an OAuth Client ID (Other). Download as creds.json.
3. clasp login --creds creds.json with this downloaded file.
4. Add the following to appsscript.json:
"executionApi": {
  "access": "ANYONE"
}

Tim

unread,
Jul 19, 2022, 12:12:07 PM7/19/22
to Google Apps Script Community
How do we get a creds.json file?

Clark Lind

unread,
Jul 20, 2022, 1:24:18 PM7/20/22
to Google Apps Script Community
Follow those numbered steps, you should be able to download the creds.json file.
Reply all
Reply to author
Forward
0 new messages