How to retrieve an API Key credential from the instance in a mid server custom connector script?

leoniu07
Tera Contributor

I'm creating a custom connector, but can't find a way to retrieve the API Key credential defined in the instance.

It's simple if basic auth is the case by using 2 lines of code below,
var username = this.probe.getParameter("username");
var password = this.probe.getParameter("password");

However, it becomes a headache when an API key credential is created and I have no clue how to get it in the connector script.

Please help!

4 REPLIES 4

Vasantharajan N
Giga Sage
Giga Sage

this.probe.getParameters() method will return Map(<string>,<string>) and please iterate through the map where you can find the actual key for API KEY.

Add the loggers so that you will come to know the different key and value available for you to develop your connector.


Thanks & Regards,
Vasanth

Thanks Vasantharajan for quick help!

I looped through the parameters and could only find the sys_id of the credential (credential_id). and I double if there is an easy way for MID to query an instance table. Below is the result

{
agent=mid.server.qa_MIDSERVER,
glide.xmlhelper.trim.enable=true,
classic_mode=true,
__con_param__baseURL=,
source=SevOne Connector,
connector_name=,
sys_id=cb62aab51b1ac190abdc8664604bcbd2,
__con_param__connectorSysId=a00c6d431b420910abdc8664604bcb76,
password=null,
from_host=,
sys_created_on=2022-03-18 14:23:21,
sys_domain=global,
host=,
__con_param__auth=,
state=ready,
__con_param__alerts=,
probe_name=Third Party Connector Probe,
test=true,
response_to=,
from_sys_id=,
priority=0,
agent_correlator=,
script=,
probe=69397632eb1221006a668c505206fe34,
processed=,
error_string=,
sequence=17f9d6959410000001,
connector=a00c6d431b420910abdc8664604bcb76,
__con_param__ack=,
last_event=1647612559,
name=,
topic=ConnectorProbe,
parent_classic_mode=true,
script_type=javascript,
__con_param__initial_sync_in_minutes=60,
queue=output,
ecc_queue=cb62aab51b1ac190abdc8664604bcbd2,
credential_id=2307de251b5e0190abdc8664604bcb20,
username=null
}

 

 

VivekSattanatha
Mega Sage
Mega Sage

Hi Leo,

 

You could use the GlideEncrypter API to fetch the API key

 

https://community.servicenow.com/community?id=community_article&sys_id=3a325773db4c701413b5fb24399619dd

 

Regards,

Vivek

Thanks Vivek!