REST API to Integration Zscaler and ServiceNow
var vZScalerAPIKEY = "<Api Key>";
//****** Get time in miliseconds**************************//
var vDate = new Date();
var vTimestamp = vDate.getTime().toString();
var vHigh = vTimestamp.substring(vTimestamp.length - 6);
var vLow = (parseInt(vHigh) >> 1).toString();
var vApiKey = "";
while (vLow.length < 6) {
low = "0" + vLow;
}
for (var i = 0; i < vHigh.length; i++) {
vApiKey += vZScalerAPIKEY.charAt(parseInt(vHigh.charAt(i)));
}
for (var j = 0; j < vHigh.length; j++) {
vApiKey += vZScalerAPIKEY.charAt(parseInt(vLow.charAt(j)) + 2);
}
//************************Authentication to Zscaler *****************//
var vSessionId ='';
var user = "<UserName>";
var password = "<Password>";
var vAuthbody = '{"username":"'+user+'","password":"'+password+'","apiKey":"'+vApiKey+'","timestamp":"'+vTimestamp+'"}';
var vAuthentication= new sn_ws.RESTMessageV2();
vAuthentication.setEndpoint("<End Point>");
vAuthentication.setRequestHeader("cache-control","no-cache");
vAuthentication.setRequestHeader('content-type','application/json');
vAuthentication.setHttpMethod("post");
vAuthentication.setRequestBody(vAuthbody);
var vAuthResponse = vAuthentication.execute();
var vAuthResponseBody = vAuthResponse.getBody();
var vAuthHttpStatus = vAuthResponse.getStatusCode();
var cookies = vAuthResponse.getCookies();
var i;
for(i=0;i<1;i++) {
var vJID = (cookies.get(i)).split(';');
vSessionId = vJID[0];
}
gs.print(vSessionId);
gs.print(vAuthResponseBody);
gs.print(vBlockurlHttpStatus );
var vZScalerAPIKEY = "<Api Key>";
//****** Get time in miliseconds**************************//
var vDate = new Date();
var vTimestamp = vDate.getTime().toString();
var vHigh = vTimestamp.substring(vTimestamp.length - 6);
var vLow = (parseInt(vHigh) >> 1).toString();
var vApiKey = "";
while (vLow.length < 6) {
low = "0" + vLow;
}
for (var i = 0; i < vHigh.length; i++) {
vApiKey += vZScalerAPIKEY.charAt(parseInt(vHigh.charAt(i)));
}
for (var j = 0; j < vHigh.length; j++) {
vApiKey += vZScalerAPIKEY.charAt(parseInt(vLow.charAt(j)) + 2);
}
//************************Authentication to Zscaler *****************//
var vSessionId ='';
var user = "<UserName>";
var password = "<Password>";
var vAuthbody = '{"username":"'+user+'","password":"'+password+'","apiKey":"'+vApiKey+'","timestamp":"'+vTimestamp+'"}';
var vAuthentication= new sn_ws.RESTMessageV2();
vAuthentication.setEndpoint("<End Point>");
vAuthentication.setRequestHeader("cache-control","no-cache");
vAuthentication.setRequestHeader('content-type','application/json');
vAuthentication.setHttpMethod("post");
vAuthentication.setRequestBody(vAuthbody);
var vAuthResponse = vAuthentication.execute();
var vAuthResponseBody = vAuthResponse.getBody();
var vAuthHttpStatus = vAuthResponse.getStatusCode();
var cookies = vAuthResponse.getCookies();
var i;
for(i=0;i<1;i++) {
var vJID = (cookies.get(i)).split(';');
vSessionId = vJID[0];
}
gs.print(vSessionId);
gs.print(vAuthResponseBody);
gs.print(vBlockurlHttpStatus );
No comments:
Post a comment