Integrating Rails and QuickBooks Online via the version 3 API: Part 3
Tutorial and screencast use
Rails 4
, Ruby 1.9.3
, and Pow
. Be sure to watch the screencast above as I unveil more details and tidbits than can be found in the article itself.
- Continuing with Part 2, let's change the email address to test the update functionality. Go back to the browser and click 'Edit'.
- Add the following to the
update
action within thevendors_controller
. - Go back to the browser and alter the email address.
- Go back to QuickBooks Online and ascertain that the update was successful.
- Now that you can connect your Rails app to QuickBooks Online and create and update objects, let me demonstrate how to use logging to examine API interaction more closely.
- Add the following right above the update action in the
vendors_controller.rb
. - Change the email address again and hit 'Update Vendor'.
- Open the
log/development.log
def update
respond_to do |format|
if @vendor.update(vendor_params)
vendor = @vendor_service.query.entries.find{ |e| e.given_name == vendor_params[:name] }
# If you have more than 20 Vendor's use this
# vendor = @vendor_service.query("SELECT * FROM VENDOR WHERE GivenName = '#{vendor_params[:name]}'").entries.first
vendor.email_address = vendor_params[:email_address]
@vendor_service.update(vendor)
format.html { redirect_to @vendor, notice: 'Vendor was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @vendor.errors, status: :unprocessable_entity }
end
end
end
The
query.entries
line is searching over your QuickBooks vendors that match the submitted name and then returning the vendor.
def update
Quickbooks.logger = Rails.logger
Quickbooks.log = true
vendor = @vendor_service.query.entries.find{ |e| e.given_name == vendor_params[:name] }
vendor.email_address = vendor_params[:email_address]
@vendor_service.update(vendor)
# ..omitted
Stay tuned
Now you should be pretty dangerous when tackling Rails and QBO integration using the version 3 API. I do have more articles and screencasts coming so be sure to sign up for my newsletter.
- Pushed on 02/07/2014 by Christian
- QuickBooks Integration Consulting