Code Poetry
and Text Adventures

by catid posted (>30 days ago) 4:45pm Wed. Mar 6th 2013 PST
Long story short.  The magic line:

curl --data "entry.1063614982=DATATOSEND" https://docs.google.com/a/gameclosure.com/forms/d/1zYBFvzAlUZX4JWmWY1RkPxYlRJXUszLs4aWu2nt_kPt/formResponse

Henretty (at gameclosure) pointed me at a modern way to have users add themselves to a online list:

I added a new Google Form to my Google Drive account.  Once it's done, I viewed the form and tried it out.  Everything worked and my form response was stored in a Google Spreadsheet.

I inspected the HTML and found the HTML form POST link was "https://docs.google.com/a/gameclosure.com/forms/d/1zYBFvzAlUZX4JWmWY1RkPxYlRJXUszLs4aWu2nt_kPt/formResponse".  And I saw that the entry field was "entry.1063614982".  So from there, the above curl command was formulated.

It worked!

So the next step was to do the same thing in node.js:

function postEmail(email) {
  var data = "entry.1063614982=" + email;

  // Set up the request
  var req = require('https').request({
    host: 'www.docs.google.com',
    port: '443',
    path: '/a/gameclosure.com/forms/d/1zYBFvzAlUZX4JWmWY1RkPxYlRJXUszLs4aWu2nt_kPt/formResponse',
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Content-Length': data.length
    }
  });
  req.write(data);
  req.end();
}

postEmail("TESTEMAIL");

Initially this didn't work.  I got the same error people were getting here: https://github.com/joyent/node/issues/4771  To fix it I changed the URL from "docs.google.com" to "www.docs.google.com" and it started working again.

Tricky but easier than setting up a custom database/script.
last edit by catid edited (>30 days ago) 5:21pm Wed. Mar 6th 2013 PST