Accessing basic auth credentials from scheduled job

samadam
Kilo Sage

I am trying to access basic auth credentials I created from a scheduled job to be able to access rest end point. I tried to do the following but it is returning null.

var provider = new sn_cc.StandardCredentialsProvider()
var credential = provider.getCredentialByID('41cc709cdb144c101bdb5a75dc961990');

var userName = credential.getAttribute("user_name");
var password = credential.getAttribute("password");

When I use the basic auth from rest message it works, so wondering if this is the right way or is there anything else I need to set up.

5 REPLIES 5

Yes. It can only work on the discovery_credentials table. I checked on my PDI.

 

if you want to get it from the sys_auth_profile_basic table, refer below code -

var credGr = new GlideRecord('sys_auth_profile_basic');
credGr.get('6418a4c3830112104dddb329feaad32c'); //Replace with your sys_id
credGr.query();
if(credGr.next()){
gs.print("username "+credGr.username+" password "+credGr.password);
}

 


Please mark this response as correct and helpful if it assisted you with your question.