Search code examples
google-apps-scriptgoogle-sheetshttp-status-code-403google-apps-script-api

Deploying Script as Webapp directly from Sheets


Is it, at all, possible to deploy a Google Scripts as web app directly from Google Sheets?

I am trying to add a custom menu to Google Sheets where the user can programmatically deploy the file's script as a web app. And it looks like it is possible to do so by following instructions from this GitHub repo.

But for obvious reasons, I need to set projectId to equal ScriptApp.getScriptId(), so that when the Spreadsheet file is copied, this variable is dynamically set to equal to that script's unique id. However, when executing saveAndDeployNewVersion() from the custom menu I've set up (and even from inside the script itself) I always get deploymentId returned as undefined, before getting a 403 error from the final function in the chain (makeRequest_).

Is there any other approach, OR, can you point out what I'm doing wrong when implementing this script into my own project?

Request failed for https://script.googleapis.com returned code 403. Truncated server response: { "error": { "code": 403, "message": "Apps Script API has not been used in project 575477635395 before or it is disabled. Enable it by vi... (use muteHttpExceptions option to examine full response) (line 211, file "Code")


Solution

  • You need to

    1. Switch to standard GCP.
    2. Enable the apps script api for that GCP

    Also see Related answer.