I am attempting to implement the Named Credential/External Credential system following this post and am getting "System.CalloutException: Unable to fetch the OAuth token." error. Everything appears to be set up correctly. When I look at the developer console logs there is a line

NAMED_CREDENTIAL_RESPONSE NamedCallout[Named Credential Id=null, Named Credential Name=null, Status Code=0, Content-Type=null, Response Size bytes=0, Overall Callout Time ms=0, Connect Time ms=0

We initially thought that the external credential was not reaching up to the named credential for the certificate, or that there was some issue with the external credential parsing the response body. However, when we reached out to the service we are calling they reported that they didn't even see a request come through.

If we set up some code to directly call the oauth endpoint that request is received and a response is received on our end as well.

Any ideas why the external credential is not actually making the auth call?

Edited to add that the running user does have full CRUD on the UserExernalCredential object and is also correctly assigned the permission set with access to the Named Principal.

Named Credential (Generate Headers has been checked and unchecked with the same result) enter image description here

External Credential enter image description here

Http http = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = http.send(req);

Calling using the above produces an 'Unable to fetch OAuth Token' message.

Setting up a legacy Named Credential to store the url and client id and secret and then issuing a call like this is working fine. enter image description here

Http http = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = http.send(req);

It looks like perhaps in the log there is a place where it is trying to get the OAuth call, but it comes back null, and then when it tries to make the call to the endpoint it can't add a token to the header. Totally guessing. All I know for sure is that no call to the OAuth endpoint is being made at all. enter image description here



You must log in to answer this question.

Browse other questions tagged .