How I use the Quickbooks JSON API
This guide is in PHP. I’ll do another one in JS later.
Step 1: Create an app on https://developer.intuit.com/ Take note of your consumer key, secret and app id.
Step 2: Grab an Oauth PHP library. Host this file somewhere. I use this one http://unitedHeroes.net/OAuthSimple
Step 3: Inside that oauth lib, replace in your consumer and secret.
- Add the token into the ‘path’ argument. https://oauth.intuit.com/oauth/v1/get_request_token
- Add an oauth callback URL that points back to this same PHP file you’re editing.
- Replace the token authorization URL in step 2 of this library. https://appcenter.intuit.com/Connect/Begin
- Replace the get access token URL in step 3. https://oauth.intuit.com/oauth/v1/get_access_token
- Add some logging at the bottom to log out the access token and secret.
Step 4: Hit that hosted Oauth library to authorize your app and get your access keys.
Step 5: Figure out the URL you’re going to call. You can get this data from the QB API explorer https://developer.intuit.com/v2/apiexplorer?apiname=V3QBO. Example https://quickbooks.api.intuit.com/v3/company/:companyId/query?query=:query
Where :query is “SELECT * FROM Account” (or other) and :companyId is your company ID for the company you authorized with. I do these token replacemtents with a generic str_replace.
Step 6: Generate a signature. I can’t post exactly how I do this, but the meat of it is
base64_encode(hash_hmac(‘sha1’, $sbs, $secret, true));
Where $sbs is “GET & $url $nvpOfParams”. Meaning a name value pair of all the parameters from step 7 below. (Obviously aside from the signature)
Step 7: Get the headers together. You need to send the CURLOPT_HTTPHEADER in the form of
Authorization: oauth_token="$token",oauth_nonce="$nonce",oauth_consumer_key="$consumer_key",oauth_signature_method="HMAC-SHA1",oauth_signature="$sig",oauth_timestamp="$timestamp",oauth_version="1.0"
Step 8: Set POST fields. If you’re posting set ‘CURLOPT_POST’ to true, and make sure to send json_encode(d) data in ‘CURLOPT_POSTFIELDS’
Step 9: Send the request. Now just execute curl_exec
For me, I’ve set this all up in a class. And with that, I can use it like this:
$QB = require_once(“qb.php”);
$QB->call(“Item”, ”Query”, ”SELECT Name,Id FROM Item WHERE Name = ‘someName’”);// and
$QB->Call("Bill", "Read", $qbBillId);
There is more involved with sending attachments, but this should get you running.
I develop tons of ecommerce automation tools at Whitebox.co