Various methods of invoking functions in Google Apps Script

Hey Everyone, I'm Joseph from GreenFlux, LLC 👋

I'm a freelance developer and I'm currently learning Google Apps Script. I use Google Sheets as a backend for several no-code platforms, and often need to interact with that data using Apps Scripts.

For API integrations, I used to rely on 3rd party services like Zapier & Integromat. But lately I've been writing GAS functions to replace those dependencies where possible, and provide more control and customization.

which brings me to the question:

What are all the different methods of invoking Apps Script functions?

Here's what I could come up with so far. ✏️

1) Manually, via RUN button

First one is obvious. No explanation needed.

2) Using a custom function

This method allows referencing the function in a formula, and passing cell values as inputs.

 * Base64 Encodes {input1 + ':' + input2}.
 * @param {string} API Key or Client ID.
 * @param {string} Password or client Secret.
 * @return Base64 encoded token.
 * @customfunction
function createToken(apiKey,pw){
var token = Utilities.base64Encode(apiKey + ":" + pw);
return token;

Screen Shot 2021-04-19 at 4.15.39 PM.png

3) Create a trigger

Next up we have Triggers, which include quite a few option.

  • Run scripts on a schedule by adding a "Time-driven" trigger
  • Monitor for Spreadsheet/Form events
  • Monitor a calendar for updates

Screen Shot 2021-04-19 at 4.18.10 PM.png

I've used the time-driven triggers for things like periodically downloading Orders from Shopify, and the On form submit trigger for sending confirmation emails. But I haven't tried the calendar trigger yet.

4) From doGet() Or doPost()

Functions can also be called by publishing your script as a web-app and then sending a POST or GET request to the published URL. Query parameters can be passed from the URL to the script by appending the URL with key=value pairs{SCRIPT_ID}-/exec?testing=123&msg=Hello+World%21

function doGet(e) {
  var params = JSON.stringify(e);
Call Apps Script function
  return HtmlService.createHtmlOutput(params);

Screen Shot 2021-04-19 at 4.40.12 PM.png

5) Via API, Add-On or Library

In addition to web-apps, scripts can also be published as an API, Add-On or Library. I haven't used these options but I'd love to hear how others are making use of them.

6) Via Google Cloud Console?

This is another area that I'm unfamiliar with, but I have a feeling there would be a way to invoke a function via the console.

Any other methods ❓

What are you using Apps Script for, and how do you trigger your functions?

Other thoughts:

There are a few limitations I've been struggling with, when trying to integrate Google Sheets and Apps Script with other platforms.

  • Webapps can't send replies to acknowledge receipt of webhooks. And most platforms that send webhooks will pause or delete the webhook rule after so many attempts if a reply is not received.
  • Webapps can't read headers from the request that invoked them.

No Comments Yet