I understand with the help of clasp, we can deploy a script programmatically (even without logging in to the Apps Script editor); however, I was wondering if there are similar functions that allow for us to invoke those APIs directly from the Apps Script editor.
I found the following resources that help with deploying via HTTP GET and POST requests -
- projects.versions.create: Before a script can be deployed, it needs to have a non-zero version available
- projects.deployments.create: Once we have a new version number, we can invoke this API to deploy a script
Unfortunately, I couldn't find any reference apart from this example snippet that could help to invoke these in a way similar to what/how we do other script services ex: SpreadsheetApp or ScriptApp or PropertiesService etc.
<script src="https://apis.google.com/js/api.js"></script>
<script>
/**
* Sample JavaScript code for script.projects.versions.create
* See instructions for running APIs Explorer code samples locally:
* https://developers.google.com/explorer-help/guides/code_samples#javascript
*/
function authenticate() {
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/script.projects"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
gapi.client.setApiKey("YOUR_API_KEY");
return gapi.client.load("https://content.googleapis.com/discovery/v1/apis/script/v1/rest")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.script.projects.versions.create({
"resource": {}
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: "YOUR_CLIENT_ID"});
});
</script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>
I understand the above is JavaScript and not specifically useful for Apps Script but...
Trying to see if there's an Apps Script (browser editor) version of
gapi.client.script.projects.versions.create