Google Apps Script - Receive Web Request (doGet)

 In this post, I am going to share how to receive a web request using Google Apps Script.


What is Google Apps Script?

Google Apps Script (GAS) is a script to automate Google App Suite like Google Sheets.

It is basically the Google version of Excel VBA.


Introduction

On a Google Sheet, go to Tools > Script editor.

You can add the following code to set "Hello" on A1.

function myFunction() {

  SpreadsheetApp.getActiveSheet().getRange('A1').setValue('Hello');

}

Click Run.

After a few seconds, you will see a notification to authorize the script on the first run.

Once authorization is done, go back to the Google Sheet to see "Hello" has been added:


doGet

Next, replace the script with the following:

function doGet(e) {

  SpreadsheetApp.getActiveSheet().getRange('B1').setValue('World!');

  return ContentService.createTextOutput("ok");

}

This time, click on Deploy > "New development"

"Select Type" > "Web app" > ... > Deploy.

"ok" is displayed when you access the generated URL, and "World!" is added on B1 on your Google Sheet.


doGet + param

You can get the parameter like:

function doGet(e) {

  var name = e.parameter.name;

  SpreadsheetApp.getActiveSheet().getRange('B1').setValue(name);

  return ContentService.createTextOutput("ok");

}


Comments

Popular posts from this blog

Selenide: Quick Start

Minikube Installation for M1 Mac

Server Testing Tools: Serverspec, InSpec, Testinfra, Goss