Error working with google apps script locally in VSCode using CLASP and push command - google-apps-script

I have cloned a google apps script project but when trying to deploy the changes with the push command I get the following error:
PS D:\evcPRD> clasp push
No valid D:\evcPRD.clasp.json project file. You may need to create or clone a project first.
Any idea how to solve this?
Thank you

Related

Is there a way to restore previous Google Apps Script Editor Versions

Is there a way to restore previous Google Apps Script Editor Versions?
I accidentally deleted a big portion of my code in the Google Script Editor. In the new editor, I do not see a way to restore versions.
In the old editor, I can go to File > See version history (please see image).
Unfortunately, this only goes back a few hours.
Is there a way to retrieve a version from yesterday?
TIA
You can try reverting to the legacy editor to access your script revision by clicking on the "Use legacy editor" button on the top right of the Apps Script window.
Even if you weren't already using clasp, when you created those versions, you can still use it now to retrieve the code for them. However, this only works if you created an explicit version of the code, under deployments, even if you didn't actually deploy them.
First install NPM, then:
npm i #google/clasp -g # install clasp
clasp login # login to your Google account
mkdir some_folder
cd some_folder
clasp clone <ScriptId> # replace <ScriptID> with your script id
clasp pull --versionNumber X # replace X with version number you want

Not able to push files using clasp push command

I am able to get the files using clasp pull command but not able to update the files using clasp push command. It says "No files to push".
When I run command clasp status then it shows all of my project files in "Ignore files". Previously it was working completely and the problem occurred yesterday when I changed my laptop.
I also tried making .claspignore file and it also did not work.
For reference, please see the screenshot.
Please help.
I think for me I found the issue after using trying
clasp version "YOUR_VERSION_STRING".
I got a console message to enable API access. Once I enabled that I was able to make pushes. It's funny because I was able to clone and pull just fine.
So this is the Settings URL and then make sure that "Google Apps Script API Access" is on.

Clasp Could not read API credentials. Are you logged in globally?

I'm logging in with clasp login --creds <file> which produces a local .clasprc.json file.
It says that I am logged in, but when I run another command I get:
Could not read API credentials. Are you logged in globally?
Any thoughts on why its not looking at my local clasprc file first?
Currently using version clasp v. 2.2.0
I ran into the same problem on Windows 10 and found that you need to login both globally and locally to use clasp run. There should be a .clasprc.json file in both your project folder and user folder.
I think I have finally found the solution for the same problem
Follow along with the comments from this github issue
Add the "oauthScopes" field to your local code and push it to your app
If you can't push, then copy-paste it to manifest file in the browser
Then you have to publish the app, and there were few things I've done, not sure which one helped. In the app in browser:
add the app version in File->Manage Versions
Publish -> Deploy as API executable
try to login with clasp and creds.json file
try to run something clasp run testRun
it may show the error that you're missing some oauth permissions, but it will list which ones, and you can add them
In my case, one weird thing that also helped was to enable some Google API
so in the app in browser: Resources -> Advanced Google Services -> enable some API
then try to do clasp run
if it works, you can disable the API that you have enabled previously.
Hope that helps

CLASP Local Login

I'm trying to figure out how to set up a local login file for my google scripts project in order to set it up so it'll work in an automated deploy process.
As far as I can tell, clasp login will create a file in your home directory which authenticates you with scripts.google.com, but that file isn't applicable to to local logins because it's missing some properties like "project_id".
When looking for how to create a file to run with clasp login --creds {file} there doesn't seem to be a straight forward way to generate one of those files in your local directory, which is how I would like to set up my deployment pipeline.
Most of the documentation on the internet says that you can create your own file by navigating to your GCP project and exporting a service account json file, but I don't know how to tell which GCP project my google script project is associated with.
I'm super lost, any help would be appreciated.
Thanks,
Alex
In order to log in locally I performed these steps:
In your project, make sure it's associated with a project id
(in the legacy editor > resources > cloud platform project > set your project id)
Then go to https://console.cloud.google.com/apis/credentials?authuser=0&project=your-project-id, create an Oauth2.0 clientid, and download your client secret and save it locally
From there you can locally log in by running clasp login -creds /path/to/file
Thanks to ALE13 and Error retrieving access token: TypeError: Cannot read property 'project_id' of undefined

clasp : unknown option creds

I'm trying to run apps script locally using clasp. I'm following https://github.com/google/clasp/blob/master/docs/run.md to get set up . I'm logged in. Foolowing the directions:
$ clasp login
Logging in globally...
� Authorize clasp by visiting this url:
https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&scope=https%3A%2F%2Fwww.google........
Authorization successful.
Default credentials saved to: ~\.clasprc.json (C:\Users\me\.clasprc.json).
$ clasp open --creds
error: unknown option `--creds'
My project files are on the E drive.
If you are to lazy to clone the clasp project, build it to finally use the --creds option, you can just open the url:
https://console.developers.google.com/apis/credentials?project=...
with the parameter project with a value like: project-id-7006438181792679938
The ability to clasp open --creds was added in commit 0cd4d12. This commit came after the current release of 1.7.0
If you are not self-compiling clasp, then you do not have this functionality yet. To compile clasp, review the developer guide.