Unable to retrieve credentails stored in credential store within service now

giovannaeth
Tera Contributor

Hi There,
I am trying to write a Rest API script that will help me connect upto an remote isntance. The remote instance uses an API key to authenticate. I have stored the key as an "API key" credential in service now cred store.
when trying to access the key with the below script, i get an error

try {
var credId = 'TE_CREDENTIAL_ID';
gs.info("Credential ID: " + credId);

var cred = new sn_auth.GlideCredentialProvider().getCredential(credId);
gs.info("Credential Object: " + JSON.stringify(cred));

if (!cred) {
gs.error("Credential object is null or undefined.");
} else {
gs.info("Token: " + cred.getPassword());
}

} catch (e) {
gs.error("Error: " + e);
}
I get this error , i am running this within scripts-background webpage

*** Script: Credential ID: TFE_CREDENTIAL_ID
*** Script: Error: TypeError: undefined is not a function.: no thrown error

 Any help would be appreciated

Thanks,

 

0 REPLIES 0