I would like to mimic the functionality under "Switch to a different standard Cloud project" here using the Apps Script API in Python. When I create a Script Project using the API it gets created such that it uses a Default Cloud Project and from the API documentation it's unclear how to change that.
SCRIPT_CODE = '''
function myFunction() {
# OMITTED -- this contains the actual code that the script runs
}
'''.strip()
MANIFEST = '''
{
"timeZone": "America/New_York",
"exceptionLogging": "CLOUD",
"executionApi": {
"access": "MYSELF"
},
}
'''.strip()
# Authenticate using OAuth 2.0
# AUTHENTICATION CODE OMITTED
service = build('script', 'v1', credentials=creds)
# Create a new project using the Apps Script API
request = {'title': 'My Script Project'}
response = service.projects().create(body=request).execute()
script_id = response['scriptId']
# Upload two files to the project
request = {
'files': [{
'name': 'Test generate script from python',
'type': 'SERVER_JS',
'source': SCRIPT_CODE
}, {
'name': 'appsscript',
'type': 'JSON',
'source': MANIFEST
}]
}
response = service.projects().updateContent(
body=request,
scriptId=script_id).execute()
# Create a new version using the Apps Script API
request = {'scriptId': script_id}
response = service.projects().versions().create(scriptId = script_id, body = request).execute()
version_number = response['versionNumber']
# Create a new deployment using the Apps Script API
request = {
"description": f"Deployment of script {script_id}",
"scriptId": script_id,
"versionNumber": version_number
}
response = service.projects().deployments().create(scriptId = script_id, body = request).execute()
print(json.dumps(response, indent=2))
deployment_id = response["deploymentId"]
# Run the script using the Apps Script API
request = {
"function": "myFunction"
}
I end up getting the below error, I believe because the authentication is with a Standard Google Cloud Project but the Apps Script Project uses a Default Google Cloud Project on creation.