If you've ever needed to enable users to self-provision to a Cisco Spark room, you have a few options.  You could build a little webapp to capture the email address, and submit the email address to the Spark API.  You could use the existing Zapier + Cisco Spark integration (https://zapier.com/zapbook/cisco-spark/google-forms/).  But, you can also build this directly into the Google Form using Google Apps Script & Triggers.  I mean, why not!?


The process turns out to be pretty straightforward.


1) Create your Google Form (mine only included one field for the user to submit their Spark email address)

2) Open the Script Editor

3) In the Script Editor, navigate to Resources > Current Project's Triggers

4) Create a trigger for your entry-point function

5) Code!


All of the code here is JavaScript, so you if you already know JS, you're sitting pretty.  Of course, you will have to dig into Google's objects for Forms.


A few troubleshooting tips that it took me a while to discover.  I'm sure there are more.


1) To output to stdout/stderr, use Logger.log().  The results of which are shown under the View > Logs menu item.

2) To see the execution output, navigate to View > Execution Transcript


Here is the code that I created that will add a user to a room.  This isn't designed for a team room, mind you.


function addToRoom(url, token, room) {
  // Get the active form, the one that we setup the trigger on
  var form = FormApp.getActiveForm();

  var formResponses = form.getResponses();
  // Because getResponses() gets all of the responses
  // Just get the last form response
  Logger.log(formResponses.length - 1);
  var formResponse = formResponses[formResponses.length - 1];

  Logger.log("Getting items in response");
  var itemResponses = formResponse.getItemResponses();

  var item = itemResponses[itemResponses.length - 1];

  var email = item.getResponse();

  var payload = JSON.stringify({ 'roomId': room, 'personEmail': email });
  var headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token };
  var url = url + '/memberships';
  var options = {
   'method': 'post',
   'headers': headers,
   'payload': payload
  var response = UrlFetchApp.fetch(url, options);