• Murali Mohan Mandadi
  • NEWBIE
  • 5 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
We are trying to replace custom settings with Named credentials in one of our application. So we are trying to move all custom settings data into named credentials and trying to connect the third party application using Per User (Identity Type) Password Authentication (Authentication Protocol) Named credential, getting the 401-Unauthorized error.

Named Credentials Created:
Identity Type - Per User
Authentication Protocol - Password Authentication

Code Snippet executed in Anonymous window:
String method = 'POST';
String IMPLCaseId = 'IM-25147';
String RelatedIMPLCaseId;
String groupNumber = 'A1723';

GCwGetBPIDRequest.QQGroupInfo qqgroupInfo = new GCwGetBPIDRequest.QQGroupInfo(IMPLCaseId, RelatedIMPLCaseId, groupNumber);
GCwGetBPIDRequest getBPIDReq = new GCwGetBPIDRequest();
getBPIDReq.ServiceType = 'IMPL';
getBPIDReq.SFDCUserName = [select Id, Name, username from User where Id = :UserInfo.getUserId()].Name;
getBPIDReq.SubType = 'GetBPID';
getBPIDReq.Implementation = qqgroupInfo;

System.debug(' getBPIDReq### ' + getBPIDReq);

HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
req.setEndpoint('callout:API_Pega_Callout_PegaUser1/PRRestService/P2EREST/Account/ProcessServiceRequest');
req.setMethod('POST');

req.setBody(getBPIDReq.generate());
req.setTimeOut(120000);

system.debug('req.getEndpoint ---------------> ' + req.getEndpoint());
system.debug('req.getHeader ---------------> ' + req.getHeader('Authorization'));
system.debug('HTTP REQUEST BODY ---------------> ' + req.getBody());

Http http = new Http();
res = http.send(req);
system.debug('HTTP RESPONSE BODY ---------------> ' + res.getBody());

Getting the Below Error:
Error 401--Unauthorized:
The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.46) containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field (section 14.8). If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains

What could be the possible reason for this? 
Any help would be appreciated.
We are trying to replace custom settings with Named credentials in one of our application. So we are trying to move all custom settings data into named credentials and trying to connect the third party application using Per User (Identity Type) Password Authentication (Authentication Protocol) Named credential, getting the 401-Unauthorized error.

Named Credentials Created:
Identity Type - Per User
Authentication Protocol - Password Authentication

Code Snippet executed in Anonymous window:
String method = 'POST';
String IMPLCaseId = 'IM-25147';
String RelatedIMPLCaseId;
String groupNumber = 'A1723';

GCwGetBPIDRequest.QQGroupInfo qqgroupInfo = new GCwGetBPIDRequest.QQGroupInfo(IMPLCaseId, RelatedIMPLCaseId, groupNumber);
GCwGetBPIDRequest getBPIDReq = new GCwGetBPIDRequest();
getBPIDReq.ServiceType = 'IMPL';
getBPIDReq.SFDCUserName = [select Id, Name, username from User where Id = :UserInfo.getUserId()].Name;
getBPIDReq.SubType = 'GetBPID';
getBPIDReq.Implementation = qqgroupInfo;

System.debug(' getBPIDReq### ' + getBPIDReq);

HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
req.setEndpoint('callout:API_Pega_Callout_PegaUser1/PRRestService/P2EREST/Account/ProcessServiceRequest');
req.setMethod('POST');

req.setBody(getBPIDReq.generate());
req.setTimeOut(120000);

system.debug('req.getEndpoint ---------------> ' + req.getEndpoint());
system.debug('req.getHeader ---------------> ' + req.getHeader('Authorization'));
system.debug('HTTP REQUEST BODY ---------------> ' + req.getBody());

Http http = new Http();
res = http.send(req);
system.debug('HTTP RESPONSE BODY ---------------> ' + res.getBody());

Getting the Below Error:
Error 401--Unauthorized:
The request requires user authentication. The response MUST include a WWW-Authenticate header field (section 14.46) containing a challenge applicable to the requested resource. The client MAY repeat the request with a suitable Authorization header field (section 14.8). If the request already included Authorization credentials, then the 401 response indicates that authorization has been refused for those credentials. If the 401 response contains

What could be the possible reason for this? 
Any help would be appreciated.