Access the QuickBooks Online API with OAuth2

OAuth2 required for new Intuit Developer Accounts

Starting July 17th, 2017 all new Intuit Developer accounts will need to use OAuth2 for API access. Here is how to use the QboApi gem and OAuth2.

OAuth2 for new Intuit Developer Accounts.

Choosing an OAuth2 gem or not

I really won't bother trying to re-invent the wheel by rolling your own OAuth2 code. That said, the OAuth2 2-legged process is simpler than the 3-legged OAuth 1a process and if you do want to roll your own OAuth2 code take a look at Intuit's Python example for a good starting point.

As for me, I'll choose to leverage the Rack-OAuth2 gem as I like its ability to directly set endpoints.

Spinning up an OAuth2 example

Clone the qbo_api gem, switch into the new directory, and bundle

$ git clone git://github.com/minimul/qbo_api && cd qbo_api
$ bundle

Create a .env file with the client_id and client_secret provided within the App settings page. See Fig. 2.

export QBO_API_CLIENT_ID=
export QBO_API_CLIENT_SECRET=

Make a new app, I called this one QboApi OAuth2 Inc then go into its settings and then click on the Keys tab to get the client id and client secret. Put those values in the .env file.

Set the OAuth2 callback or redirect URI to http://localhost:9393/oauth2-redirect

Massively IMPORTANT step

Start up the example app

$ shotgun example/app.rb

Firing up the QboApi sample app.

Goto https://localhost:9393/oauth2

Make sure to use localhost and not 127.0.0.1. Intuit only allows the host name localhost for OAuth2 sandbox callbacks.As you can see in the example/app.rb file the callback URI is also properly set to localhost and not 127.0.0.1.

Click on the 'Connect To QuickBooks' button, Sign in, and click on Authorize.

If you are not already signed in, you are going to sign in with your Intuit Developer credentials in case you might be confused. In short you are signing in and connecting your QuickBooks app's sandbox to your QuickBooks app's "App". Clear as mud? Lastly, click "Authorize".

Let's test the new access token.Success. We retrieved Sandbox customer # 5 &dash; "Dukes Basketball Camp".Reference the example/app.rb to see how to make a basic QuickBooks API call with the QBO API gem.Comment on this article?