The company I work for right now is migrating its accounting software from EasyACCT to Quickbooks, largely due to my insistence that it would be more flexible. So, armed with this “more flexible” software, I started thinking about how to automate some of our more complex (and, therefore, error prone) tasks.
In the process, I stumbled across the Intuit Developer Network, and in particular it’s Quickbooks SDK. In short, Quickbooks provides a COM object that allows you to send and receive (XML) messages between QB and an external application. Despite my unexcitement at the prospect of anything involving much XML, I realized this could let us automate more than I’d anticipated, so I signed up and downloaded the SDK (which is primarily documentation).
Then came the tricky part.
I vastly prefer programming in Ruby to other languages I’ve tried, and although the examples I saw were in Visual Basic and there is an abstraction layer for (at least) VB, I knew ultimately I would prefer Ruby. But then I ran into the snag. How to use Ruby to connect to the COM object? I’ve never tried the WIN32OLE library, so I had a bit of a learning curve, but now it’s working well.
So, for the curious, a quick example:
# Open Session
qb = WIN32OLE.new("QBXMLRP2.RequestProcessor")
qb.invoke "OpenConnection", '', 'MyApplicationName'
ticket = qb.invoke("BeginSession", "", 2) # 2 is DontCare open mode
xml = ".." # See SDK docs
result = qb.invoke("ProcessRequest", ticket, xml)
# Do whatever with result
# Repeat as desired
# End Session
qb.invoke "EndSession", ticket
qb.invoke "CloseConnection"
qb = nil
Turned out to be quite simple. The rest is just dealing with the XML, which is well covered in the SDK docs.
Update: Just found a Quickbooks SDK library for Ruby (docs, I think). Project page lists it as Pre-Alpha though.