authentication failing in ServiceNow getting error 1401
Hi Team,
I trying to get the devices from the logicmonitor into servicenow, it is throwing an error authentication failed.
{"data":null,"errmsg":"Authentication failed","status":1401}
I have compared postman and token and below script token everything is perfect.
Below is the script. can you please help me where is the mistake.
var ACCESS_ID = 'test';
var ACCESS_KEY = 'abc';
var ACCOUNT_NAME = 'cde';
var epoch = (new Date()).getTime();
var id = 2;
var resourcePath = '/device/devices';
var data= '';
var requestVars = 'GET' + epoch + resourcePath;
var HexUtil =
{
convertByteArrayToHex : function(byteArray)
{
var hex = "";
byteArray.forEach(function(byteValue) { hex += HexUtil.convertByteToHex(byteValue); });
return hex;
},
convertByteToHex : function(b)
{
var hexChar = ["0", "1", "2", "3", "4", "5", "6", "7","8", "9", "a", "b", "c", "d", "e", "f"];
return hexChar[(b >> 4) & 0x0f] + hexChar[b & 0x0f];
}
};
var key = "lma_Bmz]H_625^5H[EQi9U627pdg}8yy(-56X-hsiL7~e^s)9~56ee+^Mh)i3DKXLODZmNTRhNTUtMDM2MC00ZTY5LTkyNWItZGIwNjZmMDMyZTg5L4kmWbA";
key = encodeURIComponent(key);
key = GlideStringUtil.base64Encode(key);
var msg = requestVars;
msg = encodeURIComponent(msg);
var mac = new GlideCertificateEncryption();
signature = mac.generateMac(key, "HmacSHA256", msg);
gs.print(signature);
// Yes! bp7ym3X//Ft6uuUn1Y/a2y/kLnIZARl2kXNDBl9Y7Uo=
var bytes = GlideStringUtil.base64DecodeAsBytes(signature);
gs.print(JSON.stringify(bytes));
gs.print(bytes.length);
// Yes! [110,-98,-14,-101,117,-1,-4,91,122,-70,-27,39,-43,-113,-38,-37,47,-28,46,114,25,1,25,118,-111,115,67,6,95,88,-19,74]
var hex = HexUtil.convertByteArrayToHex(bytes);
gs.print(hex);
// Yes! 6e9ef29b75fffc5b7abae527d58fdadb2fe42e7219011976917343065f58ed4a
var hexB64 = GlideStringUtil.base64Encode(hex);
gs.print(hexB64);
var token = 'LMv1 ' + ACCESS_ID + ':' + hexB64 + ':' + epoch;
gs.info('Devices = ' +token);
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://cde.logicmonitor.com/santaba/rest/device/devices');
request.setHttpMethod('GET');
request.setRequestHeader('Authorization', token);
//request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Content-Type", 'application/json');
var response = request.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log("test==="+httpStatus+responseBody);
if (httpStatus == 200) {
var temJson = JSON.parse(responseBody);
var aTA = temJson.data;
gs.log("aTA ==="+aTA);
}
Thank You,
Sai.
Hello,
@sai If you haven’t already, I would suggest creating a support ticket so I, or another Support Engineer, can better assist you with this integration issue.