Skip to content

Instantly share code, notes, and snippets.

Created June 13, 2013 09:44
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save acarrillo/5772508 to your computer and use it in GitHub Desktop.
Save acarrillo/5772508 to your computer and use it in GitHub Desktop.
On Google Spreadsheet form submission, push new entry to a MailChimp subscription list with an `onformsubmit` trigger. Uses the MailChimp API and Google Apps Script.
var API_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var mc_base_url = '';
var mc_list_id = 'xxxxxxxxxx';
var mc_double_optin = false;
* Uses the MailChimp API to add a subscriber to a list.
function sendToMailChimp_(fn, ln, em, yr){
var payload = {
"method": "listSubscribe",
"apikey": API_KEY,
"id": mc_list_id,
"email_address": em,
"double_optin": mc_double_optin,
"update_existing": false
var options = {
"method": "post",
"payload": payload
var response = UrlFetchApp.fetch(mc_base_url,options);
* Trigger function. Based on Google Script tutorial.
* @param {Object} e The event parameter for form submission to a spreadsheet;
* see
function onFormSubmit(e) {
var fname = e.namedValues['Name'][0].split(" ")[0];
var lname = e.namedValues['Name'][0].split(" ")[1];
var email = e.namedValues['Email'][0];
var year = e.namedValues['Stuyvesant Graduation Year'][0];
* Main function. Creates onFormSubmit trigger.
function myFunction(){
// Was separated line by line for debugging purposes.
var sheet = SpreadsheetApp.getActive();
var a = ScriptApp.newTrigger("onFormSubmit");
var b = a.forSpreadsheet(sheet);
var c = b.onFormSubmit();
var d = c.create();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment