Skip to content

Instantly share code, notes, and snippets.

@palaniraja
Created October 8, 2017 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save palaniraja/d0bd2280a38ada815aef2ba407ee55ea to your computer and use it in GitHub Desktop.
Save palaniraja/d0bd2280a38ada815aef2ba407ee55ea to your computer and use it in GitHub Desktop.
Google spreadsheet - script to call HTTP Post api and update the response
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]);
}
@palaniraja
Copy link
Author

Trigger to run function every 15 min

trigger

Output spreadsheet

output

Red cells are result of conditional formatting (non 200 response)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment