Riss TT
Riss TT

Reputation: 35

Getting the Version of Google Web App Deployment

I've been trying to get the version number of a deployment and have read that I should be able to do it like this:

  var OAuthToken = ScriptApp.getOAuthToken();
  var id = ScriptApp.getScriptId();
  var url = 'https://script.googleapis.com/v1/projects/'+ id + '/deployments';
  var options = { "muteHttpExceptions": true,
              "headers": {
              'Authorization': 'Bearer ' +  OAuthToken
              }
  }
  var response = UrlFetchApp.fetch (url, options);
  Logger.log(response)
  //return JSON.parse (response.getContentText());

However what is returned is an error ... "message": "Apps Script API has not been used in project 93197649900 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/script.googleapis.com/overview?project=93197649900 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.", "status": "PERMISSION_DENIED", ... ..."

The link does not help as it just gives "You do not have sufficient permissions to view this page".

I assume this is because the Web App script is bound to a Google Sheet and not standalone?

Can anybody give me some pointers as to how I can get the deployed version number otherwise?

Thanks Dave

Upvotes: 0

Views: 589

Answers (1)

TheAddonDepot
TheAddonDepot

Reputation: 8964

UPDATE

I suspect that you may also need to switch your script project to use a Standard GCP Project and enable the Apps Script API on that project. See documentation linked below for instructions:

https://developers.google.com/apps-script/guides/cloud-platform-projects


Go to the settings page of your Apps Script dashboard to enable the API. See link below:

https://script.google.com/home/usersettings

You will also need to update your manifest (appsscript.json) and add the appropriate scopes to fetch data from the deployments endpoint. So open the Apps Script editor and do the following:

  • Go to your project's overview page by clicking the info icon (in the left sidebar), scroll to the bottom of the page and copy your list of current scopes.
  • Go to your Apps Script project's settings page by clicking the gear icon in left sidebar and click the checkbox for the setting Show "appsscript.json" manifest file in editor.
  • Go back to the main editor by clicking the editor icon (in the left sidebar) and open the manifest (appsscript.json) and add your existing scopes, plus the https://www.googleapis.com/auth/script.deployments scope as follows:
{
   // other manifest properties
   ...
   ...

   "oauthScopes": [
       "...scope pulled from overview...", 
       "...scope pulled from overview...",
       "https://www.googleapis.com/auth/script.deployments"
   ]
}

Once the Apps Script API is enabled and your manifest is properly configured you can fetch the version number of your deployment using your script.

Upvotes: 2

Related Questions