Search code examples
authenticationoauthsdktokenquickbooks

Authenticate quickbooks account using the API


Since Quickbooks has an API, I figured out that we can feed the transaction details on the fly with it. So I did some research to implement an application.

From what I found out, we can utilize the SDK and send http requests to push data into quickbooks. The problem I have is with the authentication. I have initialized the tokens as follows to create an object in the given class.

String consumerKey = "...";
        String consumerSecret = "...";
        String accessToken = "...";
        String accessTokenSecret = "...";
        String appToken = "...";
        String companyId = "...";

            OAuthAuthorizer oauth = new OAuthAuthorizer(consumerKey,consumerSecret, accessToken, accessTokenSecret);
            Context context = new Context(oauth, appToken, ServiceType.QBO, companyId);
            DataService service = new DataService(context);

The issue here is that I have to keep the token values of the merchants individually in a database to authenticate them if this approach is used. But I believe that there should be a better way.

In the QB API explorer I cannot see and endpoint for Authentication. Would you be able to let me know a better way to authenticate a quickbooks account using the API.


Solution

  • 3-legged OAuth is the only way to generate QBO tokens. Either you have to persist the tokens(as you mentioned) or you need to let your app user go through the OAuth flow(using 'Connect to QB' button). In the 2nd approach you can store the tokens in the session.