forked from nebari-dev/nebari-users-create-from-google-form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code.js
61 lines (52 loc) · 1.78 KB
/
Code.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Google Apps Script script that handles form submissions and sends data to a
// Lambda function using an HTTP POST request.
function onSubmitForm(e) {
var formAttributes = e.response.getItemResponses();
sendFormDataToLambda(formAttributes);
}
function sendApiRequest(username, password, coupon, pyvista) {
const scriptProperties = PropertiesService.getScriptProperties();
const url = scriptProperties.getProperty('LAMBDA_URL');
const auth_key = scriptProperties.getProperty('LAMBDA_AUTH_KEY');
var headers = {
"Content-Type": "application/json"
};
var payload = {
"username": username,
"password": password,
"pyvista": pyvista,
"coupon": coupon,
"auth_key": auth_key,
};
var options = {
"method": "post",
"headers": headers,
"payload": JSON.stringify(payload)
};
Logger.log("payload");
Logger.log(payload);
var response = UrlFetchApp.fetch(url, options);
// Handle the response
var responseData = JSON.parse(response.getContentText());
Logger.log("responseData");
Logger.log(responseData);
}
function sendFormDataToLambda(formAttributes) {
var formData = {}
for (var i = 0; i < formAttributes.length; i++) {
var attribute = formAttributes[i];
var name = attribute.getItem().getTitle();
formData[name] = attribute.getResponse();
}
Logger.log("formAttributes");
Logger.log(formData);
var Username = formData['Username']
var Password = formData['Password']
var Coupon = formData['Coupon']
var PyvistaVal = formData['Attending PyVista Tutorial?']
var Pyvista = false
if (PyvistaVal.toLowerCase() === "yes") {
Pyvista = true;
}
sendApiRequest(Username, Password, Coupon, Pyvista)
}