Thursday, January 3, 2013

Integrating Google App Engine & Quickbooks

Introduction

   Based of a need from a friend; he wanted to me to build a very simple web-site which allowed
  • An user to quickly search for Items (that he had defined in his quickbook accounting software).
  • Show the details of the item, including price & quantity that he had in the warehouse.
  • An automated process that will sync with quickbooks say every 30 min.
  • The development & maintenance cost should also be low.
  • Develop custom search criteria, not supported by default query in quick book. 
   There are many options for this ex:
  • E-commerce software which integrates with quickbook.  (This was the best option and we took this approach).
  • Open source CMS (ex: Wordpress) + Commercial Plugin that integrates with quickbook and host the same.
  • An app from Intuit Marketplace.
  • Custom in-house development and hosting.

Technologies

As an opportunity to experiment / learn, I took this scenario to implement a solution based on the following technologies :
  •   Google App Engine (GAE).
  •   Quickbook's Web Connector.
  •   Google datastore.
  •   Google Web Toolkit (GWT).

Pre-Requisite

I am going to assume that you know the above mentioned technologies/at least heard of the same. If not please do a search on the same; there are tons of tutorials/articles about them that I don't want to repeat.

Why Quick book web connector (QBWC)?

Quick book offers various integration options (ex: QB SDK, Intuit Web APP, Quickbook Web connector). I choose Quickbook web connector for the reasons I am more proficient in java vs .Net.

Since QBWC is the one which initiates the conversation with the hosted webservice; this is also ideal. This means that we would not have to expose quickbook to the internet. No headaches of opening firewall ports etc..

Since the communication implemented webservice and QBWC is HTTPS and authenticated session; this also makes it ideal that eves drop of traffic will not happen.

Why GAE ?

For the website, I am choosing to develop and host in Google Cloud as a Google App Engine (GAE). Some of the reasons I choose GAE are :
If the amount of data usage/ page traffic is less (based on daily quota); you could practically run this free.
GAE manages instances based on input requests and they are load balanced too. Instances are spawned & managed automatically; and less administrative headaches.
The administrative dashboard GUI also offers all monitors and controls across various instances.


I am sure that other PAAS/SAAS providers like Amazon, SalesForce also offer something similar, for now I am sticking with GAE and not comparing the differences between them.


For the data store I choose Google data store over MySQL; just so I can experiment with a No-SQL based datastore.I am not going to challenge the fact that MySQL (in google cloud) is better option.

Flow

  • QBWC will run in the local infrastructure as a background service and communicates with QuickBook. At regular intervals of time, It will invoke the identified / hosted web service (QB sync service) and handle the various requests.
  • Data will be stored in the Google Datastore.
  • Users interact via the various servlets/GWT modules exposed as front-end GUI.

Source code

In the below sections I am going to give just a brief overview of the identified components as to how it was implemented. For your reference, The code is hosted in GitHub : GAEqB
The demonstrated code is just a proof of concept (POC) code; to demonstrate the solution works. 

QB Sync service

In order to interact with QuickBooks, using QBWC we would have to implement the webservice as  defined by the   QBWC WSDL. QBWC initiates and communicates to the webservice.

According to QBWC guide, the java code was developed using Apache Axis. This might not work in GAE, hence we have to generate the service from scratch. In order for us to develop a web service, that follows the above service contract, and host in GAE; we would have to do a bottom up approach. This means that we define the java class (with appropriate @webmethod annotations) and then use java's wsgen utility to generate the wsdl and JAXB classes. 

In order to follow the namespace; the service definition class has to be part of the package "com.intuit.developer". Refer to the implemented class "com.intuit.developer.QBSyncService". All the necessary service method has been defined. As mentioned above I was able to use the wsgen utility to generate the wsdl / jaxb related classes.

As for the POC; the implementation class does the following :


  • Authenticates the user credentials from QBWC and sends a valid response for further communication.
  • Sends a request to get defined item list (50 rows at a time)
  • On receiving the item list; parses the response and stores the item as entities in the google data store.  
Unlike CXF & Axis, defining the service does not mean that the service will be exposed and client could interact directly. With GAE, we would have to develop a servlet (pass-thru) which would take the request and forward to appropriate service method. The return from the service method is passed back as response. This means that we also would have to marshall and un-marshall the soap request/response.

In the source code; refer to the class "ca.effacious.professional.gaeqb.qbsync.QBSyncServlet" for the servlet which does the above.

QBWC's configuration files

In order for QBWC to communicate with the web service; we would have to configure the same. Configurations for QBWC are first defined in an xml based configuration file; this is then added to the QBWC application list. The configuration file contains such things as url for the web-service; url for support; fileid; owner id etc.. More details on this configuration can be found in the QBWC programmers guide.

Local QBWC

For a local/developnment QBWC to GAE (local) server, there is no magic. The GAE servlet was also not https based hence it was pretty plain. A sample definition is found in the file "data/GAEqB.qwc".

GAE Hosted service + QBWC

When the service is hosted in GAE; the above mentiond non-https based communication will not work.QBWC mandates that in production environment it requires the communication to be HTTPS based. At the least QBWC checks the presence of a security certificate.

GAE apps can be communicated via HTTPS; but the certificate is more generic certificate that is same across all hosted apps. For a proper implementation; The app url would have to be set as part of a domain and you would have to get a certificate for the domain.

I dont have a domain, neither a certificate (paid service). I found a work around though (not suggested for real production service).First i got a temporary certificate from verisign (/GAEqB/war/GAECert.cert). I then packaged the same as part of the web application. Once deployed the certificate can be access via URL. Now in the QBWC configuration file (/GAEqB/data/GAE_GAEqB.qwc); I defined the above URL as a :CertURL" parameter. This hack/work-around worked; QBWC does not seem to validate the credentials etc.. on it.

Google Data Store (GDS)

As  mentioned earlier. Based on the response; the item information were parsed and specific attributes (name, full name etc..) were choosen and stored as "Item Entities" in the GDS. Instead of having the item entities as rootless; they all belonged to a common ancestor "ITEMParent". For the Entity Key, I used the listId as the key.

Refer to class "ca.effacious.professional.gaeqb.service.ItemSyncStore"; for the implementation.

GWT

For the front end; I developed a simple GWT module servlet. The servlet had a item query text field, into which an user would put in the name of the item to be searched. The servlet would look an item based on the name (name was indexed property); once found it would populate the resultant table.

Retrospective

  • This POC proved that developing a GAE app that interacts with Quick book is possible.
  • Building an app like this GAEqB is also a cheaper custom option to develop and host; as Google cloud is cheaper.
This POC had developed a base level code (QBWC WSDL services, pass thru servlet); this could now be enhanced to build a complete website on this. If you have such an idea, we could talk!!!

Retrospective

Last words



Till next time, "Vanakkam"

2 comments: