I am working on integrating Salesforce with Quickbooks using Oauth 2.0. I am able to get Access token and Refresh token with the help of client_d and consumer_secret. The scope of access token is - com.intuit.quickbooks.accounting. The problem is when I use the fetched Access Token to make API request via Postman, it is working fine. But when I tried to make an API call from Apex class I get the following error:
General Authentication ErrorAuthenticationErrorGeneral: SRV-110-Authentication Failure , statusCode: 401
I am using following code to make the API call :
String accessToken = '<access_token>'; String endPoint = 'https://sandbox-quickbooks.api.intuit.com/v3/company/<Sandbox_Id>/invoice/145?minorversion=4'; HttpRequest httpReq = new HttpRequest(); HttpResponse httpRes = new HttpResponse(); Http http = new Http(); httpReq.setMethod('GET'); httpReq.setEndPoint(endPoint); httpReq.setHeader('Accept','*/*'); httpReq.setHeader('Content-Type','application/json'); httpReq.setHeader('charset','UTF-8'); httpReq.setHeader('Authorization' , 'Bearer '+accessToken); httpRes = http.send(httpReq);
Can anyone please let me know what I am doing wrong. Thanks in advance.
PS: I have edited the code. The above code is working fine.