Created
October 8, 2017 14:27
-
-
Save palaniraja/d0bd2280a38ada815aef2ba407ee55ea to your computer and use it in GitHub Desktop.
Google spreadsheet - script to call HTTP Post api and update the response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function autoLogin() { | |
/* | |
//Trying to do the below curl request as google spreadsheet scheduler | |
curl -X POST \ | |
http://myserver.compute.amazonaws.com/api/users/login \ | |
-H 'cache-control: no-cache' \ | |
-H 'content-type: application/json' \ | |
-d '{ | |
"email" : "emailid@gmail.com", | |
"password" : "mysecretpassword", | |
"type": "user" | |
}' | |
*/ | |
var formData = { | |
'email': 'emailid@gmail.com', | |
'password': 'mysecretpassword', | |
'type': 'user' | |
}; | |
var options = { | |
'method' : 'post', | |
'payload' : formData | |
}; | |
var start = new Date(); | |
Logger.log('Before calling api: ' + start) | |
var response = UrlFetchApp.fetch('http://myserver.compute.amazonaws.com/api/users/login', options); | |
var end = new Date(); | |
Logger.log('After calling api: ' + end) | |
var responseCode = response.getResponseCode() | |
Logger.log(responseCode) | |
addRow(start,end,responseCode) | |
} | |
function addRow(start,end,response){ | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var range = sheet.appendRow([start,end,response]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trigger to run function every 15 min
Output spreadsheet
Red cells are result of conditional formatting (non 200 response)