1

Due to Google Apps Script forcefully pushing "Rhino" to "V8" engine, Applications are moving from Rhino to V8 automatically. So our applications are asking "scopes" that need to be specified manually in "appscript.json" file.

Please check the below image:

Application Issue

File :-

Code.gs

When I update like below, it works fine.

appsscript.json

Our concern is that we have more than 100 applications in production, we cannot update this manually everytime. Can you please help us how to update without any issue in production?

  • 2
    Look into [tag:google-apps-script-api] – TheMaster Mar 03 '20 at 07:57
  • 1
    I specifically meant the info page of that tag, which will contain documentation with regards to programmatic manipulation of apps scripts. – TheMaster Mar 03 '20 at 10:56
  • 2
    You would need to do a file search to find all Apps Script files, get the file IDs, and then use the REST API to get the appsscript.json file, change the setting, and then update the file. First [Get Content](https://developers.google.com/apps-script/api/reference/rest/v1/projects/getContent) and then [Update Content](https://developers.google.com/apps-script/api/reference/rest/v1/projects/updateContent) So, it's a process with multiple steps. – Alan Wells Mar 03 '20 at 13:23
  • Hello Alan, Thanks for the steps. But i think we need to publish again one by one separately. Isn't it? – Ramachandra-Sah GANESH Mar 04 '20 at 04:41
  • 1
    The migration to V8 shouldnt be having issues with the scopes used, could you please share a sample of what your code in line 105 looks like? – Mateo Randwolf Mar 04 '20 at 11:51
  • I have updated in post. Please to check – Ramachandra-Sah GANESH Mar 05 '20 at 08:08
  • 1
    Didnt you have this ```https://www.googleapis.com/auth/userinfo.email``` scope before the migration to ```v8```? – Mateo Randwolf Mar 10 '20 at 12:23

1 Answers1

1

Using clasp

You can update the manifest files in batch by using the CLASP project (it uses Apps Script API under the hood) and a utility script in Node.js or your poison of choice to control the workflow. General steps you need to take are:

  1. Clone a project with clasp clone "YourScriptIdHere"

  1. Update the appsscript.json file with the required scopes. Since manifest is saved at the root of the project, I would do something like this (with Node.js):
const { writeFile } = require("fs").promises;

const addScope = async (scopes) => {

  const pathToManifest = "appscript.json";

  const manifest = require(pathToManifest);

  const { oauthScopes = [] } = manifest;

  oauthScopes || ( manifest.oauthScopes = oauthScopes ); //guard against first scope

  oauthScopes.push(...scopes);

  await writeFile(pathToManifest, JSON.stringify(manifest));
}


  1. Push the updates to the project with clasp push. Since you are changing the manifest, use the --force option or you will have to approve each upload. Note that as of 2020, the project does not yet support partial updates, so all files will be replaced. Use .claspignore file to ensure you do not accidentally push the whole node_modules folder or similar.

  1. Redeploy the projects with clasp deploy. The command is customizable, so do not worry about having multiple deployments.