Api key in client script

kiwi07
Tera Contributor

I am trying to create a catalog and my requirement is to create 2 values in the catalog

1. a referencefield whose value will be from sys_alias table for which I have created 1 record in connection & credential alias and have provided an API key for the same

2. a lookup select field whose values will get populated onchange of the reference filed  

 

I am trying to write a client script onchange of the first field and trying to make a rest api call in the script , but the challenge is how do I pass the api key from the first field so that I can authenticate the api and send the response .

 

I have tried the below option but they don't provide any useful info 

alert(g_form.getDisplayValue('alias_selected'));
alert(g_form.getValue("alias_select"));

 

is there a way to achieve this or any other alternate that i can try 

1 ACCEPTED SOLUTION

@kiwi07 Okay Got it. Gliderecord to the API key table where they are stored and pass the alias name and return the API key

Example:

IF servicenow is alias

OmkarKumbhar_0-1674469409320.png

 

Key will be stored in below connection table

OmkarKumbhar_1-1674469458317.png

Gliderecord connection table with the name as Servicenow alias and return the API key

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

View solution in original post

9 REPLIES 9

@kiwi07 you can make use of the Client script and Script include as mentioned pervioulsy

When you are selecting the Alias pass the alias value to script include and check if the alias is the "Sample Alias" make a rest call and return value back to Client script and set.

Smiliary you can check other alias in SI using If Else loop and call the rest messgae and return value

 

One more clarification @kiwi07  have you configured the Rest messgaes whih you are going to invoke in Script include which will give you the API keys?

 

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

@Omkar Kumbhar may be i am not able to explain properly , API key is already added inside the alias, let me try to explain in a diff way, i will write the client script as below

 

var request = new sn_ws.RESTMessageV2();
request.setEndpoint('ENDPOINT of third party tool');
request.setHttpMethod('POST'); //mention here POST or GET

/*Use one of the below statement to set authentication*/
request.setRequestHeader('Authorization','Basic SU5UTFxBNjEzNjIzOklORllAMTAwOA==');

//Set here how you are sending the data i.e. XML or JSON
request.setRequestHeader("Accept","application/xml");
request.setRequestHeader('Content-Type','application/xml');

the question is how do I pass the API key that I have added in the alias below 

request.setRequestHeader('Authorization','<sample_alias>');

@kiwi07 if you are wrinting this code on client side you can use and try

request.setRequestHeader('Authorization','g_form.getValue('Alias field name'));

 

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.

@Omkar Kumbhar  Tried it but this just gives the name of the alias , we have API key inside the alis is there a way to get that ?

g_form.getValue('Alias field name')

 

kiwi07_0-1674468276116.png

 

@kiwi07 Okay Got it. Gliderecord to the API key table where they are stored and pass the alias name and return the API key

Example:

IF servicenow is alias

OmkarKumbhar_0-1674469409320.png

 

Key will be stored in below connection table

OmkarKumbhar_1-1674469458317.png

Gliderecord connection table with the name as Servicenow alias and return the API key

If I was able to help you with your case, please click the Thumb Icon and mark as Correct.