Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. psychemedia created this gist Jun 9, 2010.
    16 changes: 16 additions & 0 deletions webhook demo for Google spreadsheet onFormSubmit event
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    // Simple spreadsheet, with first sheet containing form submission repsonses
    // when the form is submitted:
    // 1) grab the latest response,
    // 2) post it to a third party service via an HTTP POST
    function testWebhook() {
    var ss = SpreadsheetApp.openById(SPREADSHEET_ID);
    var form=ss.getSheets()[0];
    var lr=form.getLastRow();
    var el=form.getRange(lr,2,1,1).getValue();
    var t=el;
    //The following escape palaver is gleaned from a Google help forum...
    var p="val1="+encodeURIComponent(t).replace(/%20/g, "+")+"&val2="+encodeURIComponent(form.getRange(lr,3,1,1).getValue()).replace(/%20/g, "+");

    // Here's where we do the callback...
    var x=UrlFetchApp.fetch('http://www.postbin.org/YOURPASTEBINID',{method: 'post', payload: p});
    }​