Sending Data to n8n from Google Forms

You can send data from Google Sheets to n8n via Simple Google Apps Script.

This script is originally authored by @mskian for Google Forms to Pushbullet. I have made little changes to it.

Paste the Below Script into Google Apps Script and Set the Trigger to FormSubmit

Please change the values according to your requirements.

It currently support two values from Google Forms. (You can add more)

function onFormSubmit(e) {
  var url = "WEBHOOKURL"; //n8n WebHook URL
  var Field1 = ' ';
  var Field2 = ' ';

  var form = FormApp.openById("FORMID"); // Copy the Form ID from the URL
  var formResponses = form.getResponses();

  var formResponse = formResponses[formResponses.length - 1];
  var itemResponses = formResponse.getItemResponses();
  var response1 = itemResponses[0]; // Field Starts from 0 (For Example if Name Text box in Google Form has the ID 0)
  var response2 = itemResponses[1];

  response1 = Field1 + response1.getResponse();
  response2 = Field2 + response2.getResponse();

  var data = {
    "response1": response1,
    "response2": response2
  };
  var options = {
    method: "post",
    headers: {
      "Content-Type": "application/json"
    },
    payload: JSON.stringify(data),
  };
  var response = UrlFetchApp.fetch(url, options);
}

If you face any issues. Please comment below.

1 Like