Jump to content
Sign in to follow this  
misc_bb

Delphi integration with Quickbooks using REST

Recommended Posts

Posted (edited)

Anyone integrating an API with Delphi (currently using Delphi Sydney 10.4) with accounting software like Quickbooks?

 

I wonder if anyone encountered an issue with REST components integration with Quickbooks. Currently, we already have an implementation with Xero and MYOB using the same structure which is working really well. However, when I implemented the same with Quickbooks I got a empty JSON string with no errors at all or whatsoever. 

 

Quickbooks API did return me an authentication code but exchanging this code for the access token leaves me nothing. It just return an empty JSON string with no errors or exception. Any idea where I can further check on this within the Delphi environment? I'm also requesting a trace for my API integration with Quickbooks support to see if the request really push thru.

 

Any input would be appreciated. Many thanks!

Edited by misc_bb

Share this post


Link to post
Posted (edited)

I guess not all APIs are created equal. I was able to figure out my problem by changing the body parameters to:  TRESTRequestParameterKind.pkREQUESTBODY to TRESTRequestParameterKind.pkGETorPOST

This is one of the function (Exchanging the code for tokens) we have for Quickbooks API integration. I have Xero and MYOB almost exactly the same code but this one wants to be different.

Different APIs have different way of interacting with the Delphi REST component. It's probably the API design. In their API documentation they indicated that this is part of the "Body", so we also indicate that its part of the request body in our code but then it has a different result. So just in case you encounter these issues, sometimes it's trial and error. :classic_biggrin:

 

    RESTRequest := TRESTRequest.create(nil);
    RESTRequest.Client := TRESTClient.create(RESTRequest);
    RESTRequest.SynchronizedEvents := False;

    RESTRequest.Client.UserAgent := qb_UserAGent;
    RESTRequest.Client.BaseURL := 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer'; 
    RESTRequest.Client.Accept := 'application/json';
    RESTRequest.Client.ContentType := 'application/x-www-form-urlencoded';
    RESTRequest.Client.Params.AddItem('Authorization', QuickbooksGetAuthorization, TRESTRequestParameterkind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]); //QuickbooksGetAuthorization - calls for the Base64 encoded authorization
    RESTRequest.Client.Params.AddItem('Host', 'oauth.platform.intuit.com', TRESTRequestParameterkind.pkHTTPHEADER, [TRESTRequestParameterOption.poDoNotEncode]);  //not sure if this was really required

    RESTRequest.Params.AddItem('grant_type', 'authorization_code', TRESTRequestParameterKind.pkGETorPOST);
    RESTRequest.Params.AddItem('code', authCode, TRESTRequestParameterKind.pkGETorPOST);  //authCode - variable that stores the authentication code
    RESTRequest.Params.AddItem('redirect_uri', qb_RedirectURI, TRESTRequestParameterKind.pkGETorPOST);  //qb_RedirectURI - variables that stores the redirectURI

    RESTRequest.Method := rmPOST;
    RESTRequest.Response := TRESTResponse.Create(RESTRequest);
    RESTRequest.Execute;

    Result := RESTRequest.Response.Content;

Just sharing maybe some of you wants to implement the same 🙂

Edited by misc_bb
  • Like 1

Share this post


Link to post

Thanks - could be useful.

Were you tempted to use the "free" CDATA connectors ? I've tried and they seem to work - if a little (lot!) slow....

 

 

Share this post


Link to post

We were actually using Indy with Xero OAuth 1.0 but we just want to take advantage of the new features that the new Delphi versions is offering. So far all good with some few hiccups along the way :classic_biggrin: but was able to get around with it. 

Share this post


Link to post
On 3/15/2021 at 5:50 PM, TimWinstanley said:

Thanks - could be useful.

Were you tempted to use the "free" CDATA connectors ? I've tried and they seem to work - if a little (lot!) slow....

 

 

Free only for the first year it seems. I was watching a recent Embarcadero webinar TandCoffee or somesuch and they weren't sure if that was the case either.
I use Quickbooks Desktop Accountant at work.

Share this post


Link to post

The CData connectors are generic crap, and their license fees are exorbitant.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×