forked from IanMulvany/sage-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gscript.js
84 lines (68 loc) · 1.86 KB
/
gscript.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function lastUpdated(){
Logger.log("hola");
// var lastrow = CountColA();
// Logger.log(lastrow);
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[1];
var lastRow = sheet.getLastRow();
Logger.log(lastRow);
var range = sheet.getRange(lastRow,1);
var submitted = range.getValue();
Logger.log(submitted);
var range = sheet.getRange(lastRow,2);
var name = range.getValue();
Logger.log(name);
var range = sheet.getRange(lastRow,3);
var email = range.getValue();
Logger.log(email);
var range = sheet.getRange(lastRow,4);
var interest = range.getValue();
Logger.log(interest);
var payload =
{
"name": name,
"email": email,
"interest": interest,
"submitted": submitted
} ;
return payload ;
}
function CountColA(){
var sheet = SpreadsheetApp.getActiveSheet();
var data = sheet.getDataRange().getValues();
for(var i = data.length-1 ; i >=0 ; i--){
if (data[i][0] != null && data[i][0] != ''){
return i+1 ;
}
}
}
function testPOST() {
var url = "https://sage-bridge.herokuapp.com/from_gdocs";
var payload = lastUpdated();
var headers = {
"Authorization" : "Basic " + Utilities.base64Encode("john" + ':' + "asff")
};
var params = {
"method":"POST",
"Content-Type" : "application/json",
"payload" : payload,
"followRedirects" : true,
"muteHttpExceptions": true,
"headers":headers
};
Logger.log(params);
var response = UrlFetchApp.fetch(url, params);
var rc = response.getResponseCode();
var responseText = response.getContentText();
if (rc !== 200) {
// Log HTTP Error
Logger.log("Response (%s) %s",
rc,
responseText );
// Could throw an exception yourself, if appropriate
}
else {
// Successful POST, handle response normally
Logger.log( responseText );
}
}