Web Apps  |  Apps Script  |  Google for Developers (2024)

If you build a user interface for a script, you can publish the script as aweb app. For example, a script that lets users schedule appointments withmembers of a support team would best be presented as a web app so thatusers can access it directly from their browsers.

Both standalone scripts andscripts bound to Google Workspace applicationscan be turned intoweb apps, so long as they meet the requirements below.

Requirements for web apps

A script can be published as a web app if it meets these requirements:

  • It contains a doGet(e) or doPost(e) function.
  • The function returns an HTML serviceHtmlOutput object or aContent serviceTextOutput object.

Request parameters

When a user visits an app or a program sends the app an HTTP GET request,Apps Script runs the function doGet(e). When a program sends the app an HTTPPOST request, Apps Script runs doPost(e) instead. In both cases, the eargument represents an event parameter that can contain information about anyrequest parameters. The structure of the event object is shown in the tablebelow:

Fields
e.queryString

The value of the query string portion of the URL, or null if no query string is specified

name=alice&n=1&n=2
e.parameter

An object of key/value pairs that correspond to the request parameters. Only the first value is returned for parameters that have multiple values.

{"name": "alice", "n": "1"}
e.parameters

An object similar to e.parameter, but with an array of values for each key

{"name": ["alice"], "n": ["1", "2"]}
e.pathInfo

The URL path after /exec or /dev. For example, if the URL path ends in /exec/hello, the path info is hello.

e.contextPath Not used, always the empty string.
e.contentLength

The length of the request body for POST requests, or -1 for GET requests

332
e.postData.length

The same as e.contentLength

332
e.postData.type

The MIME type of the POST body

text/csv
e.postData.contents

The content text of the POST body

Alice,21
e.postData.name

Always the value "postData"

postData

For instance, you could pass parameters such as username and ageto a URL as shown below:

https://script.google.com/.../exec?username=jsmith&age=21

Then, you can display the parameters like so:

function doGet(e) { var params = JSON.stringify(e); return ContentService.createTextOutput(params).setMimeType(ContentService.MimeType.JSON);}

In the above example, doGet(e) returns the following output:

{ "queryString": "username=jsmith&age=21", "parameter": { "username": "jsmith", "age": "21" }, "contextPath": "", "parameters": { "username": [ "jsmith" ], "age": [ "21" ] }, "contentLength": -1}

Deploy a script as a web app

To deploy a script as a web app, follow these steps:

  1. At the top right of the script project, click Deploy > New deployment.
  2. Next to "Select type," click Enable deployment typessettings > Web app.
  3. Enter the information about your web app in the fields under "Deployment configuration."
  4. Click Deploy.

You can share the web app URL with those you would like to use your app,provided you have granted them access.

Test a web app deployment

To test your script as a web app, follow the steps below:

  1. At the top right of the script project, click Deploy > Test deployments.
  2. Next to "Select type," click Enable deployment typessettings > Web app.
  3. Under the web app URL, click Copy.
  4. Paste the URL in your browser and test your web app.

    This URL ends in /dev and can only be accessed by users who have edit accessto the script. This instance of the app always runs the most recently savedcode and is only intended for testing during development.

Permissions

The permissions for a web app differ depending how you choose to executethe app:

  • Execute the app as me—In this case, the script always executesas you, the owner of the script, no matter who accesses the web app.
  • Execute the app as user accessing the web app—In this case, the scriptruns under the identity of the active user using the web app. This permissionapproach causes the web app to show the email of the script owner when the userauthorizes access.

Embed your web app in Google Sites

In order to embed a web app in Google Sites, it must first bedeployed. You alsoneed the Deployed URL from the Deploy dialog.

To embed a web app into a Sitespage, follow these steps:

  1. Open the Sites page where you'd like to add the web app.
  2. Select Insert > Embed URL.
  3. Paste in the web app URL and then click ADD.

The web app appears in a frame in the page's preview. When you publishthe page, your site viewers may need to authorize the web app before itexecutes normally. Unauthorized web apps present authorization prompts tothe user.

Web Apps and Browser History

It can be desirable to have an Apps Script web app simulate a multi-pageapplication, or one with a dynamic UI controlled via URL parameters.In order to do this well, you can define a state object to represent the app'sUI or page, and push the state into the browser history as theuser navigates your app. You can also listen to history events so that your webapp displays the correct UI when the user navigates back and forth with thebrowser buttons. By querying the URL parameters at load time, you can have yourapp dynamically build its UI based on those parameters, allowing the user tostart the app in a particular state.

Apps Script provides two asynchronous client-side JavaScript APIs to assistwith creating web apps that are linked to the browser history:

  • google.script.historyprovides methods to allow dynamic response to browser history changes. Thisincludes: pushing states (simple Objects you can define) onto the browserhistory, replacing the top state in the history stack, and setting a listenercallback function to respond to history changes.

  • google.script.url providesthe means to retrieve the current page's URL parameters and URL fragment, ifthey are present.

These history APIs are only available to web apps. They are notsupported for sidebars, dialogs or add-ons. This functionality is alsonot recommended for use inweb apps embedded in a Google Sites.

Web Apps  |  Apps Script  |  Google for Developers (2024)
Top Articles
The relationship between political instability and stock market performance: An analysis of the MSCI index in the case of Pakistan
Binance founder Changpeng Zhao sentenced to 4 months in prison after plea deal
Foxy Roxxie Coomer
Po Box 7250 Sioux Falls Sd
Dannys U Pull - Self-Service Automotive Recycling
Is Sam's Club Plus worth it? What to know about the premium warehouse membership before you sign up
Palm Coast Permits Online
Pga Scores Cbs
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
<i>1883</i>'s Isabel May Opens Up About the <i>Yellowstone</i> Prequel
Apnetv.con
Tiger Island Hunting Club
Brenna Percy Reddit
Santa Clara Valley Medical Center Medical Records
Chastity Brainwash
Why Is Stemtox So Expensive
Shariraye Update
Ella Eats
Eka Vore Portal
Craighead County Sheriff's Department
Ess.compass Associate Login
Craigslist Missoula Atv
V-Pay: Sicherheit, Kosten und Alternativen - BankingGeek
Earl David Worden Military Service
Jenna Ortega’s Height, Age, Net Worth & Biography
Slim Thug’s Wealth and Wellness: A Journey Beyond Music
Happy Homebodies Breakup
Tokyo Spa Memphis Reviews
Goodwill Of Central Iowa Outlet Des Moines Photos
San Jac Email Log In
Ihs Hockey Systems
R/Mp5
Helpers Needed At Once Bug Fables
Rugged Gentleman Barber Shop Martinsburg Wv
Otis Offender Michigan
Ellafeet.official
Tas Restaurant Fall River Ma
Ursula Creed Datasheet
Smith And Wesson Nra Instructor Discount
Thelemagick Library - The New Comment to Liber AL vel Legis
Worcester County Circuit Court
Barstool Sports Gif
Cocorahs South Dakota
Stranahan Theater Dress Code
2024-09-13 | Iveda Solutions, Inc. Announces Reverse Stock Split to be Effective September 17, 2024; Publicly Traded Warrant Adjustment | NDAQ:IVDA | Press Release
Chase Bank Zip Code
Iupui Course Search
Is TinyZone TV Safe?
Lagrone Funeral Chapel & Crematory Obituaries
login.microsoftonline.com Reviews | scam or legit check
Latest Posts
Article information

Author: Greg O'Connell

Last Updated:

Views: 6517

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Greg O'Connell

Birthday: 1992-01-10

Address: Suite 517 2436 Jefferey Pass, Shanitaside, UT 27519

Phone: +2614651609714

Job: Education Developer

Hobby: Cooking, Gambling, Pottery, Shooting, Baseball, Singing, Snowboarding

Introduction: My name is Greg O'Connell, I am a delightful, colorful, talented, kind, lively, modern, tender person who loves writing and wants to share my knowledge and understanding with you.