Go back to the main page

Integrating Rails and QuickBooks Online via the version 3 API: Part 3

This article is over 2 years old. Proceed with caution.

Regards ♨ – Minimul



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.

  • Code from screencast is available on Github
    1. Continuing with Part 2, let's change the email address to test the update functionality. Go back to the browser and click 'Edit'.
    2. Stop at the edit view so we can add some code to the vendors controller.
    3. Add the following to the update action within the vendors_controller.
    4.   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]
              format.html { redirect_to @vendor, notice: 'Vendor was successfully updated.' }
              format.json { head :no_content }
              format.html { render action: 'edit' }
              format.json { render json: @vendor.errors, status: :unprocessable_entity }
      The query.entries line is searching over your QuickBooks vendors that match the submitted name and then returning the vendor.
    5. Go back to the browser and alter the email address.
    6. Modify the email and click 'Update Vendor'.
    7. Go back to QuickBooks Online and ascertain that the update was successful.
    8. Go to the detail view to see if the email address was updated.
      The email address update worked!
    9. 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.
    10. Add the following right above the update action in the vendors_controller.rb.
    11. 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]
        # ..omitted
    12. Change the email address again and hit 'Update Vendor'.
    13. Open the log/development.log
    14. The quickbooks-ruby logging is demarcated with ------ New Request ------

    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.

    Comment on this article?

    New! Get the book!

    Sign up for the QuickBooks Integration Roadmapping Call!

    Don't know where to start on a QuickBooks Integration. I'll get you on solid ground, fast!