0

I am new to using Named Credentials. I created a Named Credential with following details: Identity Type: Name Credential Authentication Protocol: Password Authentication and added username and password. Generate HTTP headers as true

I am using below code to access my named credential: (API_Login_Information is the name of my named credential)

    Http h = new Http();
    HttpRequest req = new HttpRequest();
    req.setEndpoint('callout:API_Login_Information');
    req.setMethod('GET');
    HttpResponse res = h.send(req);

However, I am getting error when doing callout as the api documentation (to which I am trying to connect) says username and password are mandatory when calling the service: Ex: Lets say service name is https://www.google.com, I need to send username and password in url as below:

https://www.google.com/xml.php?_[action]=auth&login=***username****&password=****password*****

Can I achieve above requirement using named credential (when I try with out using named credential but using custom setting it is working from anonymous window and yes, they need the password in URL)

P.S: Referred to this question where sfdcfox answered we cannot use merge fields in url then is there any other way to achieve this.

3
  • Hi sfdcfox, I linked that question and your answer here but in this case, I have no control on other server and they require me to pass password and username in endpoint url. so posted as a qestion. Thx
    – sf_user
    Commented May 28, 2017 at 2:23
  • 1
    Oh. Looks like my VTC is redundant, then. I didn't see your edit until I'd linked the question. No worries. The short of it is that you'll need to arrange an alternative means of storing your username/password, such as a Custom Setting or something; NC won't help you here.
    – sfdcfox
    Commented May 28, 2017 at 2:24
  • ok. Thanks... currently I am using custom metadata to hold username and password and I will continue using them.. I wanted to try out to see if named credentials can serve my purpose. Thanks for your clarification.
    – sf_user
    Commented May 28, 2017 at 2:26

0

Browse other questions tagged .