Outbound REST API Using Mutual Authentication and Script Includes

Manohar4
Mega Contributor

Hello, 

I was able to set up Mutual Authentication using SSL for a third party Web Application. Testing REST Calls are working fine. But when I code a script include function to do the same - I am running into issues. I am testing the script includes using Automation Test Framework. 

The code in Script Include looks like this

function JustReturnME(x){	

	var restMessage = new sn_ws.RESTMessageV2();
	restMessage.setHttpMethod("post");
	restMessage.setMutualAuth("myhttps"); // Setting the Mutual Auth Protocol (Same as used in testing the simple REST Calls)
	restMessage.setEndpoint("##---MY REST URL---");		
	gs.print("MY DATA "+JSON.stringify(x));
	restMessage.setRequestBody(JSON.stringify(x));	
	var response = restMessage.execute();
	gs.print("THIS IS THE RESPONSE "+JSON.stringify(response));	
	return 'ok';	
	

	
}

The code in the Automation Test Framework looks like this

(function(outputs, steps, stepResult, assertEqual) {
    // add test script here
	var input = {"description": "create to test servicenow","name": "EARTH"};
	var result = JustReturnME(input);

	if(result == 'ok'){
		return true;
	}else{
		return false;
	}

})(outputs, steps, stepResult, assertEqual);

The error I see when I invoke the test

14:41:06.525: Exception while registering protocol: myhttps Error: Password must not be null: no thrown error

The same "myhttps" Protocol profile is working just fine in the Test REST Call Screen and not from the script include.

Could someone please help me with the setup?

Thanks in advance

 

1 ACCEPTED SOLUTION

Dear Ankur,

 

 Thanks for the response. I had 2 global parameters set for glide.httpclient.protocol.myhttps.class and glide.httpclient.protocol.myhttps.port - That were conflicting with the Rest Call Invocation - 

I have deleted those global parameters as they are not used any longer. And that has addressed the issue.

Regards,

Manohar

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Manohar,

As the message says the password seems to be empty for this testing. The reason it would be working from the other screen since the user must be already logged in I think so.

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Dear Ankur,

 

 Thanks for the response. I had 2 global parameters set for glide.httpclient.protocol.myhttps.class and glide.httpclient.protocol.myhttps.port - That were conflicting with the Rest Call Invocation - 

I have deleted those global parameters as they are not used any longer. And that has addressed the issue.

Regards,

Manohar