Workaround: Reflecting Latest Script to Deployed Web Apps Created by Google Apps Script without Redeploying

Gists

This report is a workaround for reflecting the latest Google Apps Script to the deployed Web Apps without redeploying.

Pattern 1

Of course, when the developer mode of https://script.google.com/macros/s/###/dev is used, the latest script can be used without redeploying.

But, in this case, only the permitted users can use it using the access token. when you want to achieve this using the endpoint of https://script.google.com/macros/s/###/exec without the access token, in order to reflect the latest script to Web Apps, it is required to redeploy. As another pattern, I would like to introduce a workaround for this situation.

Pattern 2

In this pattern, I would like to introduce a workaround that the latest script is reflected to the endpoint of https://script.google.com/macros/s/###/exec.

Usage

1. Create 2 Google Apps Script projects

Please create the following 2 Google Apps Script projects.

  1. For Web Apps. It supposes that the filename is “project1”.

  2. For Google Apps Script library. It supposes that the filename is “project2”.

2. Prepare sample script

Please copy and paste the following script to the script editor of “project1”.

const doGet = (e) => Lib.sample(e);

Please copy and paste the following script to the script editor of “project2”.

var sample = (obj) =>
  ContentService.createTextOutput(
    JSON.stringify({ obj, message: "Updated sample message." })
  );

3. Deploy library

Please deploy “project2” as a library. Ref Here, please copy the script ID. This script ID is the same as the library key for installation.

Please install the library to “project1” using the retrieved library key. Ref In this case, please install the library as follows. The following JSON data is the manifest file (appsscript.json).

{
  "timeZone": "### your timeZone ###",
  "dependencies": {
    "libraries": [
      {
        "userSymbol": "Lib",
        "version": "0",
        "libraryId": "### your library key ###",
        "developmentMode": true
      }
    ]
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "webapp": {
    "executeAs": "USER_DEPLOYING",
    "access": "ANYONE_ANONYMOUS"
  }
}

4. Deploy Web Apps

Please deploy Web Apps at “project1” as Execute as: Me and Who has access to the app: Anyone. Ref And, please retrieve the Web Apps URL like https://script.google.com/macros/s/###/exec.

5. Testing

As a test, a curl command is used. The sample curl command is as follows. Please use your Web Apps URL.

$ curl -L "https://script.google.com/macros/s/###/exec"

When this curl command is run, the following value is returned.

{
  "obj": {
    "contextPath": "",
    "queryString": "",
    "parameters": {},
    "parameter": {},
    "contentLength": -1
  },
  "message": "Sample message."
}

Here, please modify “project2” as follows. “Sample message.” was modified to “Updated sample message.” Please save the script.

var sample = (obj) =>
  ContentService.createTextOutput(
    JSON.stringify({ obj, message: "Updated sample message." })
  );

And, please run the above curl command again. By this, the following value is returned.

{
  "obj": {
    "contentLength": -1,
    "parameters": {},
    "queryString": "",
    "contextPath": "",
    "parameter": {}
  },
  "message": "Updated sample message."
}

You can see the value of "message":"Updated sample message." is changed from "message":"Sample message.". By this, the latest script could be reflected in the Web Apps with the endpoint of https://script.google.com/macros/s/###/exec.

Note

I posted this to the Japanese site on March 30, 2017. Ref But, I noticed that this has never been posted as my blog. So, I posted it here.

 Share!