Задача: сделать интеграцию с произвольной Гугл Формс, чтобы ее данные отправлялись в БД нашего сайта

тестовый пример тут https://docs.google.com/forms/d/1MxYelK8wZ0c_6zzw35lvUNaHsV4Y-x7FwOwfIQu6a0Q/edit

If you need to send a POST request from an Apps Script function, you can use:

UrlFetchApp.fetch()

The default type of request is a GET request, so you will need to use advanced options, and explicitly designate a POST request.

Google Apps Script Documentation – UrlFetchApp.fetch()

In order for the Apps Script project to be available, it must be published. In the script editor, click the “Publish” menu, and choose “Deploy as Web App”. There are two versions of a Web App, the development version, and the “production” version. The development version has “dev” on the end of the URL. The production version has “exec” on the end of the URL.

The “exec” version of the Apps Script URL is what you must use for the URL in your POST request to your Apps Script project.

function myFuncOnSubmit() {
// MailApp.sendEmail(“[email protected]”,
// “Subject”,
// “A new application has been submitted.\n\n” +
// “Here is the link to all Applications:\n” +
// “https://docs.google.com/spreadsheets/x/1-fdasjhFAKEfdaahfkhsa/”,
// {name:”From Name”});
//

// ИСТОНИК https://developers.google.com/apps-script/reference/forms/form-response

// Open a form by ID and log the responses to each question.(внимание айди из режима редакировани а не опроса)
var form = FormApp.openById(‘1MxYelK8wZ0c_6zzw35lvUNaHsV4Y-x7FwOwfIQu6a0Q’);
var message = “+++”;
var formResponses = form.getResponses();
for (var i = 0; i < formResponses.length; i++) {
var formResponse = formResponses[i];
var itemResponses = formResponse.getItemResponses();
for (var j = 0; j < itemResponses.length; j++) {
var itemResponse = itemResponses[j];
message +=”Response to the question “+itemResponse.getItem().getTitle()+” was “+ itemResponse.getResponse();
}
}

var rows =
{
“message” : message
};

// Because payload is a JavaScript object, it will be interpreted as
// an HTML form. (We do not need to specify contentType; it will
// automatically default to either ‘application/x-www-form-urlencoded’
// or ‘multipart/form-data’)

var options =
{
“method” : “post”,
“payload” : rows
};

UrlFetchApp.fetch(“http://wp.new-dating.com/lavi/gforms/index.php”, options);

}

Толковая статья как отправить гугл форм по мылу

https://madebymany.com/blog/supercharge-your-google-form-with-google-apps-script

By Ruslan Novikov

Интернет-предприниматель. Фулстек разработчик. Маркетолог. Наставник.