- You have already been able to run the function of Google Apps Script using Apps Script API with Python.
- When you run the function of
test1
at GAS side with the arguments of {"1": "hi", "3": "bye","a5": "yes"}
, both event[1]
and event["3"]
return undefined
.
- You want to retrieve the values
hi
and bye
with event[1]
and event["3"]
, respectively.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Issue and workaround:
When the following function is directly run at the script editor of Google Apps Script, all values of hi
, bye
and yes
are shown in the log. From this, it is found that Google Apps Script can use the key which is the number.
function myFunction() {
var event = {"1": "hi", "3": "bye","a5": "yes"};
Logger.log( event[1] ); // <--- hi
Logger.log( event["3"] ); // <--- bye
Logger.log( event["a5"] ); // <--- yes
}
When {"1": "hi", "3": "bye","a5": "yes"}
is sent with Apps Script API, the key which is the number doesn't return the value. I could also confirm this situation in my environment. In this case, each key can be retrieved. But when the key is the number, the value for the key cannot be retrieved. On the other hand, at the official document, I could confirm that struct_value
(JSON object) can be used for parameters[]
.
As another test, I ran the function test1
with the following curl command.
curl -X POST \
-H "Authorization: Bearer ###" \
-H "Content-Type: application/json" \
-d "{function: 'test1', parameters: [{'1': 'hi', '3': 'bye', 'a5': 'yes'}], devMode: true}" \
"https://script.googleapis.com/v1/scripts/###:run"
I could confirm that the same issue occurred. By this, it is considered that the module of google-api-python-client is not the reason of this issue.
From above situation, I thought that when the object is sent to the GAS side, the object might not be able to be correctly received. So as a workaround, I put event = JSON.parse(JSON.stringify(event))
at the top of function. By this, I could confirm that all values are retrieved.
Modified script:
function test1( event ) {
event = JSON.parse(JSON.stringify(event)); // Added
Logger.log( event ); // <--- {1=hi, 3=bye, a5=yes}
Logger.log( event[1] ); // <--- hi
Logger.log( event["3"] ); // <--- bye
Logger.log( event["a5"] ); // <--- yes
}
References:
If I misunderstood your question and this was not the direction you want, I apologize.