title: Google apps script ScriptApp.getService().getUrl() always returns the wrong URL
body: <p>According to the documentation, this method should return the URL of the web app:</p>
  <p><em>&quot;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.&quot;</em></p>
  <p>We have a Google Calendar add-on in which we have custom settings page (html) delivered to the clients using <code>HtmlService</code> and I have no idea how <code>ScriptApp.getService().getUrl()</code> works with versioned deployments.</p>
  <p>Here's an interesting scenario:</p>
  <p>On a fresh Google Script project, we deployed from manifest file (NOT webapp, although we have the &quot;webapp&quot; part on the manifest)</p>
  <ol>
  <li><p>First versioned deployment from manifest:</p>
  <p><code>ScriptApp.getService().getUrl()</code> correctly returns <a href="https://script.google.com/a/gong.io/macros/s/AKfycbzR21YpWNakFEisFcW1zo-tArveQ5nXj_gTRYLF4OZWkMf_Gun8Q3I2WZncfLSbjKEr/exec" rel="nofollow noreferrer">https://script.google.com/a/gong.io/macros/s/AKfycbzR21YpWNakFEisFcW1zo-tArveQ5nXj_gTRYLF4OZWkMf_Gun8Q3I2WZncfLSbjKEr/exec</a></p>
  <p>Versioned Deployment ID: <code>AKfycbzR21YpWNakFEisFcW1zo-tArveQ5nXj_gTRYLF4OZWkMf_Gun8Q3I2WZncfLSbjKEr</code></p>
  </li>
  <li><p>Made some changes, created a new versioned deployment</p>
  <p><code>ScriptApp.getService().getUrl()</code> correctly returns <a href="https://script.google.com/a/gong.io/macros/s/AKfycbxXBdBXAV7olI0NGe-uS0_4FEFZPPNXLVHml6NNNW9zYf1fLOqfLhLYsaz6FTmjduIq/exec" rel="nofollow noreferrer">https://script.google.com/a/gong.io/macros/s/AKfycbxXBdBXAV7olI0NGe-uS0_4FEFZPPNXLVHml6NNNW9zYf1fLOqfLhLYsaz6FTmjduIq/exec</a></p>
  <p>Versioned Deployment ID: <code>AKfycbxXBdBXAV7olI0NGe-uS0_4FEFZPPNXLVHml6NNNW9zYf1fLOqfLhLYsaz6FTmjduIq</code></p>
  </li>
  <li><p>We've deployed the script through <strong>Publish-&gt;Deploy as web app...</strong> Probably done this mistakenly on our production script</p>
  <p>Web app URL is <a href="https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec" rel="nofollow noreferrer">https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec</a></p>
  </li>
  <li><p>Another round of code changes to the script. This time we deployed from manifest:</p>
  <p><code>ScriptApp.getService().getUrl()</code> <strong>incorrectly</strong> returns <a href="https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec" rel="nofollow noreferrer">https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec</a></p>
  <p>Versioned Deployment ID: <code>AKfycbx29Pcs8_cpEkodrfWGklz8t_OAs87OBSEtxLMkStrya64wUV4M2ePW_tNTTWlq0_T1</code></p>
  </li>
  </ol>
  <p>Notice that this time - we got the webapp deployment ID - not the versioned deployment id.</p>
  <p>From here on, no matter what I've tried - I will ALWAYS get <a href="https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec" rel="nofollow noreferrer">https://script.google.com/a/gong.io/macros/s/AKfycbzv1gX4eim1CzTjnFc4sFNvLMw9mXCfOv4laDu-_9AKefk5jXg/exec</a> no matter what we do.</p>
  <ol>
  <li>Deleted all versioned deployments and created a new one</li>
  <li>Disabled web app</li>
  </ol>
  <p><a href="https://i.stack.imgur.com/ue6qv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ue6qv.png" alt="enter image description here" /></a></p>
  <p>As of now, everything I do ends up in <code>ScriptApp.getService().getUrl()</code> returning this URL.</p>
  <p>How can I reset it and get <code>getUrl()</code> to return the versioned deployment ID rather than a non-existing webapp deployment ID?</p>
  <p>edit: typos</p>