Reading this doc from Salesforce, it was my understanding that a named credential handled authenticating when using it to make a callout. I'm going to go out on a limb and say that it probably does, I'm just doing something wrong. I set up a named credential for Quickbooks.
In order to create that Named Credential, I had to setup an Auth. Provider.
But then when I wrote this quick snippet of code,
public Integer getClientOutstandingBalance(Id persCustId) {
String entId = [SELECT QB_Entity_Id__c FROM Account WHERE Id =: persCustId].QB_Entity_Id__c;
if ( String.isEmpty(entId) ) return 0;
String namedCredential = 'callout:Quickbooks';
String custPath = '/v3/company/[redacted]/customer/4319';
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(namedCredential+custPath);
req.setMethod( 'GET' );
HttpResponse resp = h.send(req);
System.debug('#### resp status: '+resp.getStatus());
System.debug('#### resp code: '+resp.getStatusCode());
System.debug('#### resp: '+resp.getBody());
return 0;
}
The response I get from Quickbooks is,
#### resp status: Unauthorized
#### resp code: 401
#### resp: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2018-10-03T11:23:32.531-07:00"><Fault type="AuthenticationFault"><Error code="100"><Message>General Authentication Error</Message><Detail>AuthenticationErrorGeneral: SRV-110-Authentication Failure , statusCode: 401</Detail></Error></Fault></IntuitResponse>
Is there something that I'm missing?