Getting StartedQBO3's Javascript library enables full control of all QBO objects via a simple javascript interface. To start, include the QBO3 javascript library as follows: <script type="text/javascript" src="Theme.ashx/Javascript"> To log into a QBO3 site: new qbo3.LoginObject().login({Username: "myemail@company.com", Password: "myPassword"}, function(json) { alert(json.success ? 'Logged in!': 'Bad credentials'); }); To add a new Organization to the system: new qbo3.OrganizationObject().invokeJson( All QBO3 javascript class objects support invokeJson({method}, {data}, {callbacks}), where:
To search for all organizations in the state of CA: new qbo3.OrganizationObject().invokeJson('Search', {'State': 'CA'}, function(json) { console.log('Here are the results:'); console.log(json); }); All QBO3 tables include a SQL identity column as a primary key; the Organization table has an OrganizationID. Let's assume the Acme organization has an OrganizationID of 1. // Set up a variable so we can reuse it. // By default, all AJAX calls are async (and should remain so for 'real' apps). For our purposes, however, we'll make the calls sync, so we don't need to chain callback functions. var organization = new qbo3.OrganizationObject({async: false}); // See what our current address is organization.invokeJson('Select', {'ID': 1}, function(json) { console.log('Address is ' + json.Address) }); // Change the address organization.invokeJson('Save', {'ID': 1, 'Address': '234 Center Street'}, function(json) { console.log('Address is now ' + json.Address) }); // See what our new address is organization.invokeJson('Select', {'ID': 1}, function(json) { console.log('New address is ' + json.Address) }); // An Organization inherits from Contact, which supports geo-coding. Let's geocode! organization.invokeJson('Geocode', {'Address': '234 Main Street', 'City': 'San Diego', 'State': 'CA', 'PostalCode': 92101}, function(json) { console.log(json) }); // Just geocode Acme and save it in the database; I don't need to see the lat and lng right now organization.invoke('Normalize', {'ID': 1}); Notes on the above code:
Displaying DataManipulating data via javascript and JSON is well and good, but at some point you will need to display this data to an end user. You're welcome to use javascript to do this; Handlebars is a pretty cool way to work with JSON. QBO3 also comes with a standard set of transformations (XSLTs) designed to display our data in a nice Bootstrap-based UI. To leverage the Bootstrap-based UI, make sure you include our CSS: Include an HTML element where you want to display the XHTML delivered by the QBO3 server: <div id="myResults">Loading...</div> Then, you can leverage our invokeHtml method: // Set up a variable so we can reuse it. Note that we include a target HTML element id. var organization = new qbo3.OrganizationObject({'target': 'myResults'}); // Display all Organizations in the state of California inside the myResults div tag, using the standard Organization.Search.xslt organiztaion.invokeHtml('Search', {'State': 'CA', 'Transform': 'Organization.Search.xslt'}); // Most QBO3 methods that return data include a 'default' transform; if you omit the 'Transform' parameter, the default transform will be used. // This call is functionally identical to the call above. organiztaion.invokeHtml('Search', {'State': 'CA'}); // If you prefer your own UI, create your own XSLT and call it. organiztaion.invokeHtml('Search', {'State': 'CA', 'Transform': 'My.Custom.Organization.Search.UI.xslt'}); Notes:
Extending the QBO3 javascript libraryThe Theme.ashx/Javascript method will serve up a single javascript file containing all scripts in the /Scripts folder of the web server. If you wish to include your own extensions in the QBO3 javascript library, simply add your .js file to the /Scripts folder of the QBO3 website. |