Skip to main content
All CollectionsMiscGuides leveraging external tools
Building A Custom Email Notification System
Building A Custom Email Notification System

Building a simple email notification system with Google Apps Script. (Advanced)

Jacob Payne avatar
Written by Jacob Payne
Updated over 5 years ago

This guide will walk through the steps required to build a simple Fulcrum email notification system using the Google Apps Script platform in conjunction with Fulcrum webhooks. The resulting system will send out email notifications any time a record is created, updated, or deleted in our designated Fulcrum app.

Google Apps Script

Google Apps Script is a scripting language based on JavaScript, designed for light-weight application development in the Google Apps cloud platform. This technology allows us to write simple code, directly in the browser, that leverages Google’s server infrastructure.

Quick Overview

The only requirements for this exercise are a Google Account and a Fulcrum app. The email notification will include the following information:

Subject: The subject line containing the event type (create, update, delete).
User: The user who created, updated, or deleted the record.
Record Title: The title of the record (can be any field you choose).
Record ID: The unique ID of the record, linked to the record view/edit screen in Fulcrum.
Timestamp: The Fulcrum updated at timestamp (when the record was updated).
Static Map: A Google Static Map image showing the location of the record.

Example Email Notification

Finding Your Fulcrum Info

In order to limit the email notifications to a specific app, we need to specify the ID for the app that you will get notifications for. You can easily find the ID for your app in the URL of the app dashboard. Copy everything after https://web.fulcrumapp.com/apps/ in the dashboard URL- this is your form ID.

Next, in order to grab information for particular fields that are unique to your app, we need to take a look at the form definition. You can view the form definition by making a simple call to the Forms API directly in your web browser. You will need your API key for this, so click on the red gear icon in the upper right-hand corner of the Fulcrum screen to access your settings. Click on the API Key button under your organization and copy the API Key.

View the form definition by constructing the following URL and pasting it into your browser:
https://api.fulcrumapp.com/api/v2/forms/YOUR-FORM-ID.json?token=YOUR-API-KEY

In the returned form definition JSON file, search for the record_title_key and copy the value. If you want to display additional information in your email notification, make note of the key values that match up with the labels corresponding to the fields you created in the app builder.

Getting Started with Google Apps Script

Now that we have the information we need from Fulcrum, we can begin writing the Google Apps Script, which will ultimately provide our webhook endpoint. Visit https://script.google.com and click to Create a script for a Blank Project.

Email Notification Script

Our script is going to intercept the webhook record event JSON payload, pull out the data we want, construct and send the email from our Google account. Copy the following script into the Apps Script browser editor, making sure to clear out any existing code.

See the email notifications Apps Script code here: https://gist.github.com/bmcbride/645efee454b0238d63c8

The doPost function intercepts our JSON payload from Fulcrum and passes it to the handleResponse function. Update the formId and title variables with the information you copied earlier. Update the sendTo variable with the email address to send to. You can modify the script to add attachments, bcc addresses, etc. by setting advanced MailApp parameters. The script should be fairly self-explanatory and easily customizable.

Deploying As A Web App

Once we deploy the script, we will be given a web app URL to use in Fulcrum. Make sure to save the script then click Publish -> Deploy as web app. You can give a description for the Project version (click Save New Version) then set Execute the app as: me (your email) and Who has access to the app: Anyone, even anonymous. Click Deploy and be sure to copy the web app URL.

Note- if you make any changes after initially deploying the web app, you will need to save a new version before re-publishing. Click File > Manage versions to save a new version and select the latest version when you deploy.

Configure The Fulcrum Webhook

We now have a URL endpoint to intercept our webhook payload and fire off an email notification. From the navigation pane/sidebar, click the Webhooks button then click to Add Webhook.

Webhooks are global to a Fulcrum organization, so be sure to give it a meaningful name so that you will know which app the webhook references.

Conclusion

Hopefully, this guide demonstrates the power of utilizing Google Apps Script to process Fulcrum webhooks. This is by no means limited to email notifications. This same setup could also be used to insert Fulcrum data into a Google Sheet, Fusion Table, or forward it to another REST API. GAS web apps can also be utilized as proxies to interact with the Fulcrum API without exposing your API key to the public.

Did this answer your question?