So your client wants you to query or post something to their quickbooks online (qboe) account from their rails app, this should be easy right?
Well if you are like me you probably googled "rails" and "quickbooks" and found a few interesting articles out there. What I found was they were mostly focused on quickbooks app (not quickbooks online). So if you are reading this and want to integrate with regular quickbooks, stop reading and go back to google, this is only for quickbooks online (qboe).
Note, this is the easiest way I have found, and not necessarily the best or most secure way, but if you got to get it done, this should work. (the hosted model is more secure, but its a nightmare, my big issue with it is it requires the ip you connect out on to have reverse dns that matches your application, this doesn't work for deamhost.)
Before we start, you will need a few things:
1.) Create a qboe account or get the login/password for the account you will be integrating with, I would create a trial one for now so you dont risk messing something important up.
2.) Create a IDN account (developer.intuit.com), click "Join IDN", and create a Community Developer membership which is free.
3.) Download the sdk (you need windows to do this, so fire up parallels or borrow a friends windows machine). Once you install the sdk, copy the files over to your mac. (optional but highly recommended)
3.) Register your application at with IDN at appreg.intuit.com. When you register, choose "qboe", "desktop" and "production" as options. Pick a domain name & application name and make note of these. Submit and you will need to verify via email. If this works, you will be taken to a screen that lists your applications, note your :
AppID: should be a long number
AppLogin: should be something like your domain name with app name in front
4.) Get your ticket, open a browser and go to:
Replace your YOUR-APPLICATION-ID-HERE with your application id.
Follow the screens, signin to your QBOE account, allow everything, dont require signin.
* If you mess up, you can fix this by logging in to QBOE, go to admin, connections and make changes there.
Save the ticket it presents to you (either via email or screen) in a safe place.
5.) Test out your ticket:
create an xml file called: session.xml
<?xml version="1.0" ?>
<ApplicationLogin>application login goes here</ApplicationLogin>
<ConnectionTicket>connection ticket goes here</ConnectionTicket>
<AppID>application id goes here</AppID>
Replace the relevant portions of the file.
Test with curl:
curl -v -d @session.xml -H "Content-Type: application/x-qbxml" https://webapps.quickbooks.com/j/AppGateway
You should get:
<SignonDesktopRs statusCode="0" statusSeverity="INFO">
<SessionTicket>a session ticket will be here</SessionTicket>
If you get this, then you are good to go!.
Now for the fun part, time to code, this approach uses qbXML, you will send these requests and get xml responses. I am using httpsarty to send the requests and parse the xml. I am also using erb to templatize the qbXML.
a.) Get httpsarty : git://github.com/jnunemaker/httpsarty.git
b.) Create your erb templates for the 3 calls you need to create an invoice: (get the session, get the customer, then create the invoice)
c.) Now create the httpsarty class that does the work:
Use the QBOE web interfact to do the following:
- create a client called "test company a"
- create 2 product/services, 1 called "Exterior" and one called "Interior"
Test it using the rails console:
items = ["Exterior", "Interior"]
Qboe.create_invoice("test company a",items)
check qboe and you should see a new invoice!