Need to pass the basic auth crds profile dynamically as per set parameter name

Ben138
Mega Expert

Hi Community,

 

Can you please suggest me the method to pass the basic auth crds dynamically i have list of basic crds on basic auth configuration table eg for  basic auth profile name like test, abc xyz

I need to pass whenever i am passing the parameter(i.e r.setStringParameterNoEscape('url', 'test');) here parameter is test so i need to use that basic auth profile name for auth i.e test need to pass 

r = new sn_ws.RESTMessageV2('Vcenter API', 'Getting Session ID');
r.setStringParameterNoEscape('url', 'test');

r.setMIDServer('MY_MID_SERVER');


response = r.execute();
responseBody = response.getBody();

This required in my workflow

Thanks,

Benji

1 ACCEPTED SOLUTION

VivekSattanatha
Mega Sage
Mega Sage

Hi,

 

Use the 'setAuthenticationProfile' method in RESTMessageV2 API.

 

Refer the RestMessageV2 doc

https://developer.servicenow.com/dev.do#!/reference/api/rome/server/c_RESTMessageV2API#r_RMV2-setAuthenticationProfile_S_S-anchor

 

It will look like this

 

sm = new sn_ws.RESTMessageV2("<REST_message_record>", "get");  

       //set auth profile to an basic auth profile record.
	sm.setAuthenticationProfile('basic', '1234adsf123212131123qasdsf'); 

 

View solution in original post

3 REPLIES 3

Rahul Priyadars
Giga Sage
Giga Sage

Can you let me know the Problem Statement which you want to achieve before going into Technical Solution Details?

I mean what is the use case requirement here?

Regards

RP

I am trying to provision the VM in the vcenter from the service catalog which required vcenter session ID to login . In order to login to get the session id vcenter url which will get from vmware vcenter from the selected its crds which this need to pass in rest message from the selected mid server and selected crds to active this 

 

Thanks,

Ben 

VivekSattanatha
Mega Sage
Mega Sage

Hi,

 

Use the 'setAuthenticationProfile' method in RESTMessageV2 API.

 

Refer the RestMessageV2 doc

https://developer.servicenow.com/dev.do#!/reference/api/rome/server/c_RESTMessageV2API#r_RMV2-setAuthenticationProfile_S_S-anchor

 

It will look like this

 

sm = new sn_ws.RESTMessageV2("<REST_message_record>", "get");  

       //set auth profile to an basic auth profile record.
	sm.setAuthenticationProfile('basic', '1234adsf123212131123qasdsf');