Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google apps script ScriptApp.getService().getUrl() always returns the wrong URL

According to the documentation, this method should return the URL of the web app:

"Returns the URL of the web app, if it has been deployed; otherwise returns null. If you are running the development mode web app, this returns the development mode url."

We have a Google Calendar add-on in which we have custom settings page (html) delivered to the clients using HtmlService and I have no idea how ScriptApp.getService().getUrl() works with versioned deployments.

Here's an interesting scenario:

On a fresh Google Script project, we deployed from manifest file (NOT webapp, although we have the "webapp" part on the manifest)

  1. First versioned deployment from manifest:

    ScriptApp.getService().getUrl() correctly returns https://script.google.com/a/gong.io/macros/s/AKfycbzR21YpWNakFEisFcW1zo-tArveQ5nXj_gTRYLF4OZWkMf_Gun8Q3I2WZncfLSbjKEr/exec

    Versioned Deployment ID: AKfycbzR21YpWNakFEisFcW1zo-tArveQ5nXj_gTRYLF4OZWkMf_Gun8Q3I2WZncfLSbjKEr

  2. Made some changes, created a new versioned deployment

    ScriptApp.getService().getUrl() correctly returns https://script.google.com/a/gong.io/macros/s/AKfycbxXBdBXAV7olI0NGe-uS0_4FEFZPPNXLVHml6NNNW9zYf1fLOqfLhLYsaz6FTmjduIq/exec

    Versioned Deployment ID: AKfycbxXBdBXAV7olI0NGe-uS0_4FEFZPPNXLVHml6NNNW9zYf1fLOqfLhLYsaz6FTmjduIq

  3. We've deployed the script through Publish->Deploy as web app... Probably done this mistakenly on our production script

    Web app URL is https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec

  4. Another round of code changes to the script. This time we deployed from manifest:

    ScriptApp.getService().getUrl() incorrectly returns https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec

    Versioned Deployment ID: AKfycbx29Pcs8_cpEkodrfWGklz8t_OAs87OBSEtxLMkStrya64wUV4M2ePW_tNTTWlq0_T1

Notice that this time - we got the webapp deployment ID - not the versioned deployment id.

From here on, no matter what I've tried - I will ALWAYS get https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec no matter what we do.

  1. Deleted all versioned deployments and created a new one
  2. Disabled web app

enter image description here

As of now, everything I do ends up in ScriptApp.getService().getUrl() returning this URL.

How can I reset it and get getUrl() to return the versioned deployment ID rather than a non-existing webapp deployment ID?

edit: typos

like image 747
yarinbenado Avatar asked Oct 13 '20 15:10

yarinbenado


People also ask

Where can I publish my Google Apps Script projects?

Store and share your projects in Google Drive or publish on the Chrome Web Store. Tutorials and guides to take you from writing your first script to building your application. From productivity tools to enterprise automation, see what you can build with Google Apps Script.

What is Google Apps Script used for?

Apps Script is a rapid application development platform that makes it fast and easy to create business applications that integrate with G Suite. Build with Google Feature-rich APIs let you extend Google services and build your own web applications. Code on the Web A web browser is all you need to build with Google Apps Script.

How to disable the script from being accessed as a Webapp?

Disables the script from being accessed as a web app. This method is equivalent to opening the "Publish > Deploy as web app" dialog and clicking "disable web app". Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License.

Does the script need to be published as a web app?

The script does not need to // be published as a web app; the /usercallback URL suffix replaces /edit in any script's URL. // IMPORTANT: Replace string below with the URL from your script, minus the /edit at the end.


Video Answer


1 Answers

This might to be a bug.

This issue was reported in Issue Tracker (I'm guessing you did it), and now it got forwarded internally. Posting this here to give it more visibility:

  • ScriptApp.getService().getUrl() doesn't work for versioned deployments

To anyone affected by this, please click the top-left star.

like image 183
Iamblichus Avatar answered Oct 19 '22 19:10

Iamblichus