QuickBooks Rubygem Documentation
Example Code
First include the gemrequire 'rubygems' require 'quickbooks' # The following examples will also assume including the days_and_times gem: require 'days_and_times'Next, set up your connection method and specify your SDK version (optional, if your connection is a two-way communication with QuickBooks)
# Example A: Connect to the local desktop Quickbooks. Quickbooks.use_adapter :ole Quickbooks.qbxml_version = "4.0" # -- OR skip this step and the gem will automatically ask # Quickbooks for the latest supported version. # Example B: Using the spew adapter, which just returns # the generated QBXML command string. Quickbooks.use_adapter :spew Quickbooks.qbxml_version = "6.0" # <-- or whatever version you wish # Example C: Using the HTTP adapter, which will communicate over # the network via HTTP to the # QuickBooks HTTP Bridge service on the other end Quickbooks.use_adapter :http, 'your-IP-or-dynamic-ip-name' # Note: You can also ask for the versions # available in the QuickBooks you're connected to: Quickbooks.connection.qbxml_versionsFind a Customer by name
QB::Customer.first(:FullName => "Joni Gortella")Create a new Customer
customer = QB::Customer.new(:Name => "Mack Froth", :FirstName => "Mack", :LastName => "Froth") customer.valid? # => true; Customer requires only Name. customer.saveFind all Customers created today (note that QuickBooks can't search by datetime, only by date)
customers = QB::Customer.all(:Find all Invoices for a specific CustomerFromModifiedDate => Time.today)
# Since you can pass in several OwnerIDs in the API, # always pass this argument in an array. # In Invoices, OwnerID refers to the Customer. QB::Invoice.all(:OwnerID => [customer[:ListID]])Create a new SalesOrder
sales_order = QB::SalesOrder.new( :CustomerRef => {:FullName => 'Mack Froth'}) sales_order[:SalesOrderLine] << { :ItemRef => {:ListID => '123-456-7890'}, :Desc => "Specialized Gew-Gaw", :Quantity => 2, :Amount => 22.99 } sales_order.saveCreate a TimeTracking entry
QB::TimeTracking.create( :CustomerRef => {:FullName => 'Smack Industries'}, :EntityRef => {:FullName => 'Mack Froth'}, :Duration => '1H30M', :BillableStatus => 'Billable' )Find out what parameters are available for any given query
>> QB::Invoice.query_attributes => ["TxnID", "RefNumber", "RefNumberCaseSensitive", "MaxReturned", "ModifiedDateRangeFilter", "TxnDateRangeFilter", "EntityFilter", "AccountFilter", "RefNumberFilter", "RefNumberRangeFilter", "PaidStatus", "IncludeLineItems", "IncludeLinkedTxns", "IncludeRetElement", "OwnerID"] >> QB::ItemInventory.query_attributes => ["ListID", "FullName", "MaxReturned", "ActiveStatus", "FromModifiedDate", "ToModifiedDate", "NameFilter", "NameRangeFilter", "IncludeRetElement", "OwnerID"] >> QB::Customer.query_attributes => ["ListID", "FullName", "MaxReturned", "ActiveStatus", "FromModifiedDate", "ToModifiedDate", "NameFilter", "NameRangeFilter", "TotalBalanceFilter", "IncludeRetElement", "OwnerID"]
QuickBooks is a registered trademark of Intuit, Inc.
Usage Tutorial
Runtime Setup
Quickbooks.use_adapter :ole, "app-name"
Quickbooks.use_adapter :http, "ip-address", "app-name", "password"
Quickbooks.qbxml_version = "6.0"
Quickbooks.qbxml_version = "CA3.0"
Getting Objects from QuickBooks
customers = QB::Customer.all
inactive = QB::Customer.all(:ActiveStatus => "InactiveOnly")
todd = QB::Customer.first(:FullName => ["Todd Skeet"])
ti_x = QB::Customer.all(:NameFilter => {:MatchCriterion => "StartsWith", :Name => "Ti"})
after_sally = QB::Customer.all(:MaxReturned => 7, :NameRangeFilter => {:FromName => "Sally Moore"})
sally_invoices = QB::Invoice.all(:EntityFilter => after_sally[0].to_ref, :PaidStatus => "NotPaidOnly")
sally_invoices = QB::Invoice.all(:EntityFilter => {:FullName => "Sally Moore"}, :PaidStatus => "NotPaidOnly")
play_ball = QB::ItemInventory.first(:FullName => ["Small Baseball"])
Create New Objects in QuickBooks
jerry = QB::Customer.new(:Name => "Jerry Kreid", :FirstName => "Jerry", :LastName => "Kreid") jerry.save
play_ball = QB::ItemInventory.new( :Name => "Small Baseball", :SalesPrice => "6.49", :IncomeAccountRef => {:FullName => "Sales"}, :AssetAccountRef => {:FullName => "Inventory Asset"}, :COGSAccountRef => {:FullName => "Cost of Goods Sold"}) play_ball.save
sale = QB::SalesOrder.new( :CustomerRef => jerry.to_ref, :SalesOrderLine => [{ :ItemRef => play_ball.to_ref, :Quantity => 2, :Rate => play_ball[:SalesPrice], :Desc => play_ball[:FullName] }]) sale.save
sale[:SalesOrderLine] << QB::SalesOrderLine.new( :ItemRef => {:FullName => "Small Baseball"}, :Quantity => 2, :Rate => play_ball[:SalesPrice], :Desc => play_ball[:FullName])
invoice = QB::Invoice.new( :CustomerRef => jerry.to_ref, :InvoiceLine => [{ :ItemRef => play_ball.to_ref, :Desc => play_ball[:Name], :Quantity => 2, :Rate => play_ball[:SalesPrice] }]) invoice.save
Data Extensions
QB::Customer.first(:IncludeExtData => true)
customer = QB::Customer.first customer.load_extended_data
customer.update_extended_data(key, value)
List of QuickBooks Objects
ARRefundCreditCard
Account
AccountTaxLineInfo
AppliedToTxn
BillPaymentCheck
BillPaymentCreditCard
Bill
BillToPay
BillingRatePerItem
BillingRate
BuildAssembly
CashBackInfo
Charge
Check
Class
CompanyActivity
Company
ComponentItemLine
CreditCardCharge
CreditCardCredit
CreditMemoLineGroup
CreditMemoLine
CreditMemo
CustomerMsg
Customer
CustomerType
DataEventRecoveryInfo
DataEventSubscription
DataExtDefDel
DataExtDef
DataExtDel
DataExt
DateDrivenTerms
DepositLine
Deposit
DiscountLine
Employee
EstimateLineGroup
EstimateLine
Estimate
ExpenseLine
Host
InventoryAdjustmentLine
InventoryAdjustment
InvoiceLineGroup
InvoiceLine
Invoice
ItemAssembliesCanBuild
ItemDiscount
ItemFixedAsset
ItemGroupLine
ItemGroup
ItemInventoryAssembly
ItemInventory
ItemLine
ItemNonInventory
ItemOtherCharge |
ItemPayment ItemReceipt ItemSalesTaxGroup ItemSalesTax ItemService ItemSubtotal
JobType JournalEntry
ListDeleted
OtherName
PaymentMethod PayrollItemNonWage PayrollItemWage Preferences PriceLevelPerItem PriceLevel PurchaseOrderLineGroup PurchaseOrderLine PurchaseOrder
ReceivePayment ReceivePaymentToDeposit RefundAppliedToTxn
SalesOrderLineGroup SalesOrderLine SalesOrder SalesReceiptLineGroup SalesReceiptLine SalesReceipt SalesRep SalesTaxCode SalesTaxLine SalesTaxPaymentCheckLine SalesTaxPaymentCheck ShipMethod ShippingLine StandardTerms
TaxLineInfo Template TimeTracking ToDo Transaction TxnDeleted
UIEventSubscription UIExtensionSubscription UnitOfMeasureSet
VehicleMileage Vehicle VendorCredit Vendor VendorType
WorkersCompCode |
QB::Account.query_attributes
QB::Account.query_xsd
QB::Invoice.write_xsd
QB::SalesReceipt.read_write_xsd