Simple password ServiceNow API authentication in Google script.
function SNOWsimpleAuth() { | |
// Those are environnement variables defined in File>Project properties>Script properties | |
var username = PropertiesService.getScriptProperties().getProperty('LOGIN'); | |
var password = PropertiesService.getScriptProperties().getProperty('PASSWORD'); | |
// I will use Google script UrlFetchApp class to make request, which is more powerfull than XMLHttpRequest | |
var headers = { | |
'Authorization': 'Basic ' + Utilities.base64Encode(username + ":" + password) | |
}; | |
var options = { | |
'method' : 'get', | |
'accept': 'application/json', | |
'headers':headers | |
}; | |
try{ | |
// Let's query the first incident of a SNOW testing developper instance | |
var response = UrlFetchApp.fetch("https://devXXXXX.service-now.com/api/now/table/incident?sysparm_limit=1", options); | |
}catch(e){ | |
Logger.log("caught this:" + e); | |
} | |
Logger.log("Before JSON parsed "+ response.getContentText()); | |
var responseBody = JSON.parse(response.getContentText())['result']; | |
Logger.log(responseBody.result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment