google / clasp

🔗 Command Line Apps Script Projects
https://developers.google.com/apps-script/guides/clasp
Apache License 2.0
4.59k stars 428 forks source link

clasp run [functionName] --params doesn't work #742

Open JRPoinsot opened 4 years ago

JRPoinsot commented 4 years ago

(Note: Non-breaking issues are likely not to be prioritized. Please consider a PR in addition to your issue)

Expected Behavior

clasp run setProperties --params '[{"foo":"bar"}]' Should be execute my function setProperties with a Object {"foo": "bar"}

My function : function setProperties(properties) { PropertiesService.getScriptProperties.setProperties(properties, false); }

Actual Behavior

response : Input params not Valid JSON string. Please fix and try again. A try other basic JSON format ... but same message.

Specifications

imthenachoman commented 4 years ago

Silly question but what happens if you use double quotes:?

clasp run setProperties --params "[{'foo':'bar'}]"
ChaddPortwine commented 3 years ago

I had clasp run setProperty -p ["domain" "mydomain.com"] working a few days ago. It was great.

Now, I cannot find the proper JSON format. I read here to use "...space-separated array of values such...". So I don't know what could have gone wrong?

Here is what I tried:

PC:AppsScript-CLASP user$ clasp run setProperty -p ["domain" "mydomain.com"]
Input params not Valid JSON string. Please fix and try again
PC:AppsScript-CLASP user$ clasp run setProperty -p ["domain","mydomain.com"]
Input params not Valid JSON string. Please fix and try again
PC:AppsScript-CLASP user$ clasp run setProperty -p ['domain','mydomain.com']
Input params not Valid JSON string. Please fix and try again
PC:AppsScript-CLASP user$ clasp run setProperty -p ['domain' 'mydomain.com']
Input params not Valid JSON string. Please fix and try again
PC:AppsScript-CLASP user$ clasp run setProperty -p [{'domain': 'mydomain.com'}]
Input params not Valid JSON string. Please fix and try again
PC:AppsScript-CLASP user$ clasp run setProperty -p "['domain' 'mydomain.com']"
Input params not Valid JSON string. Please fix and try again
PC:AppsScript-CLASP user$ clasp run setProperty -p '['domain' 'mydomain.com']'
Input params not Valid JSON string. Please fix and try again

Node v8.11.1 Clasp v2.3.0 MacOs BigSur v11.2.1

Update

The JSON format that works for me: '["domain","mydomain.com"]'

Additionally, I needed to run node LTS, and I was behind.

PopGoesTheWza commented 3 years ago

Just to be sure the issue still exist, can you try replacing @google/clasp 2.3.0 with forked-clasp which is more advanced?

npm uninstall -g @google/clasp
npm install -g forked-clasp
somombo commented 3 years ago

I noticed that there's not a single test case in https://github.com/google/clasp/blob/master/test/commands/run.ts for --params

Claudiney-Santos commented 3 years ago

I had the same problem.

I use windows cmd, so the parameter was "splited" because of the double quotes Cmd does not use single quotes, so I used \" instead and it worked

The correct code was something like this: clasp run "myFunction" -p "[\"test\"]"

s6fcda commented 2 years ago

I use windows cmd, so the parameter was "splited" because of the double quotes Cmd does not use single quotes, so I used \" instead and it worked

The correct code was something like this: clasp run "myFunction" -p "[\"test\"]"

@Claudiney-Santos I know this was an old reply, but thanks for pointing this out. This solved my problem. I hope this is included in the formal documentation.