1

I am writing a simple Google script to update a spreadsheet (from this Google tutorial). I deploy this script as an API executable which can be called from my computer via python code, the gist of which I include below.

api_id = 'xxxxxxxxxxxxxxxxxxxxxxxxx' # where do I specify the api version?

credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
script_service = discovery.build('script', 'v1', http=http)

request = {"function": "updateListenerStatus", # function name to call inside the Google script        
           "parameters": [data], # JSON argument passed to the function                                
           "devMode": True} # run the most recently saved instead of published version

response = script_service.scripts().run(body=request, scriptId=api_id).execute()

Every thing is working great, except I would like to utilize the version feature. From reading the documentation I see that by changing "devMode" to False I can run the most recently published version of the script instead of the most recently saved version. However, what if I want to run an older published version? I am familiar with specifying the library version when I import one Google script into another Google script, but is there any way for me to specify the version number from my python code?

2 Answers 2

1

This functionality doesn't seem to have been included yet. Since setting devMode to true makes the script run at the most recently saved version, why don't you edit the version you want to run and save it. Just edit some comments which doesn't have any impact, then save it.. That way it will run your desired script version (since it's recently saved).

Sign up to request clarification or add additional context in comments.

1 Comment

Certainly I can do that to run any desired script myself, but I would like to be able to support multiple versions at the same time. This tool will be used by many engineers and I would like changes to the script or client to be backwards compatible. Maybe there is no way to do this with Google scripts.
1

I have a workaround I've implemented which isn't super elegant but it gets the job done. Essentially I include the version number as part of the name of the function: myFunction_v1 and myFunction_v2. I create a separate Google script project which imports each published version of my original script (MyProject_v1 and MyProject_v2). I then use this new script project to route the function calls to the correct release version:

// Code.gs
function myFunction_v1() {
  MyProject_v1.myFunction()
}

function myFunction_v2() {
  MyProject_v2.myFunction()
}

function myFunction_v3() {
  MyProject_v3.myFunction()
}

When I call the function from the python client, I use the function name associated with the version of the script I want to run.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.