Package: quickbooks-pinecone
python-quickbooksA Python 3 library for accessing the Quickbooks API. Fork ofpython-quickbooksThese instructions were written for a Django application. Make sure to
change it to whatever framework/method you’re using.
You can find additional examples of usage inIntegration tests folder.For information about contributing, see theContributing Page.QuickBooks OAuthThis library requiresintuit-oauth.
Follow theOAuth 2.0 Guidefor installation and to get connected to QuickBooks API.Accessing the APISet up an AuthClient passing in yourCLIENT_IDandCLIENT_SECRET.fromintuitlib.clientimportAuthClientauth_client=AuthClient(client_id='CLIENT_ID',client_secret='CLIENT_SECRET',environment='sandbox',redirect_uri='http://localhost:8000/callback',)Then create a QuickBooks client object passing in the AuthClient, refresh token, and company id:fromquickbooksimportQuickBooksclient=QuickBooks(auth_client=auth_client,refresh_token='REFRESH_TOKEN',company_id='COMPANY_ID',)If you need to access a minor version (SeeMinor versionsfor
details) pass in minorversion when setting up the client:client=QuickBooks(auth_client=auth_client,refresh_token='REFRESH_TOKEN',company_id='COMPANY_ID',minorversion=4)Object OperationsList of objects:fromquickbooks.objects.customerimportCustomercustomers=Customer.all(qb=client)Note:The maximum number of entities that can be returned in a
response is 1000. If the result size is not specified, the default
number is 100. (SeeIntuit developer guidefor details)Filtered list of objects:customers=Customer.filter(Active=True,FamilyName="Smith",qb=client)Filtered list of objects with ordering:# Get customer invoices ordered by TxnDateinvoices=Invoice.filter(CustomerRef='100',order_by='TxnDate',qb=client)# Same, but in reverse orderinvoices=Invoice.filter(CustomerRef='100',order_by='TxnDate DESC',qb=client)# Order customers by FamilyName then by GivenNamecustomers=Customer.all(order_by='FamilyName, GivenName',qb=client)Filtered list of objects with paging:customers=Customer.filter(start_position=1,max_results=25,Active=True,FamilyName="Smith",qb=client)List Filtered by values in list:customer_names=['Customer1','Customer2','Customer3']customers=Customer.choose(customer_names,field="DisplayName",qb=client)List with custom Where Clause (do not include the"WHERE"):customers=Customer.where("Active = True AND CompanyName LIKE 'S%'",qb=client)List with custom Where and orderingcustomers=Customer.where("Active = True AND CompanyName LIKE 'S%'",order_by='DisplayName',qb=client)List with custom Where Clause and paging:customers=Customer.where("CompanyName LIKE 'S%'",start_position=1,max_results=25,qb=client)Filtering a list with a custom query (SeeIntuit developer guidefor
supported SQL statements):customers=Customer.query("SELECT * FROM Customer WHERE Active = True",qb=client)Filtering a list with a custom query with paging:customers=Customer.query("SELECT * FROM Customer WHERE Active = True STARTPOSITION 1 MAXRESULTS 25",qb=client)Get record count (do not include the"WHERE"):customer_count=Customer.count("Active = True AND CompanyName LIKE 'S%'",qb=client)Get single object by Id and update:customer=Customer.get(1,qb=client)customer.CompanyName="New Test Company Name"customer.save(qb=client)Create new object:customer=Customer()customer.CompanyName="Test Company"customer.save(qb=client)Batch OperationsThe batch operation enables an application to perform multiple
operations in a single request (SeeIntuit Batch Operations Guidefor
full details).Batch create a list of objects:fromquickbooks.batchimportbatch_createcustomer1=Customer()customer1.CompanyName="Test Company 1"customer2=Customer()customer2.CompanyName="Test Company 2"customers=[customer1,customer2]results=batch_create(customers,qb=client)Batch update a list of objects:fromquickbooks.batchimportbatch_updatecustomers=Customer.filter(Active=True)# Update customer recordsresults=batch_update(customers,qb=client)Batch delete a list of objects:fromquickbooks.batchimportbatch_deletecustomers=Customer.filter(Active=False)results=batch_delete(customers,qb=client)Review results for batch operation:# successes is a list of objects that were successfully updatedforobjinresults.successes:print("Updated "+obj.DisplayName)# faults contains list of failed operations and associated errorsforfaultinresults.faults:print("Operation failed on "+fault.original_object.DisplayName)forerrorinfault.Error:print("Error "+error.Message)Change Data CaptureChange Data Capture returns a list of objects that have changed since a given time
(seeChange data capturefor more details):fromquickbooks.cdcimportchange_data_capturefromquickbooks.objectsimportInvoicecdc_response=change_data_capture([Invoice],"2017-01-01T00:00:00",qb=client)forinvoiceincdc_response.Invoice:pass# Do something with the invoiceQuerying muliple entity types at the same time:fromquickbooks.objectsimportInvoice,Customercdc_response=change_data_capture([Invoice,Customer],"2017-01-01T00:00:00",qb=client)If you use adatetimeobject for the timestamp, it is automatically converted to a string:fromdatetimeimportdatetimecdc_response=change_data_capture([Invoice,Customer],datetime(2017,1,1,0,0,0),qb=client)AttachmentsSeeAttachable documentationfor list of valid file types, file size limits and other restrictions.Attaching a note to a customer:attachment=Attachable()attachable_ref=AttachableRef()attachable_ref.EntityRef=customer.to_ref()attachment.AttachableRef.append(attachable_ref)attachment.Note='This is a note'attachment.save(qb=client)Attaching a file to customer:attachment=Attachable()attachable_ref=AttachableRef()attachable_ref.EntityRef=customer.to_ref()attachment.AttachableRef.append(attachable_ref)attachment.FileName='Filename'attachment._FilePath='/folder/filename'# full path to fileattachment.ContentType='application/pdf'attachment.save(qb=client)Other operationsVoid an invoice:invoice=Invoice()invoice.Id=7invoice.void(qb=client)If your consumer_key never changes you can enable the client to stay running:QuickBooks.enable_global()You can disable the global client like so:QuickBooks.disable_global()Working with JSON dataAll objects includeto_jsonandfrom_jsonmethods.Converting an object to JSON data:account=Account.get(1,qb=client)json_data=account.to_json()Loading JSON data into a quickbooks object:account=Account()account.from_json({"AccountType":"Accounts Receivable","Name":"MyJobs"})account.save(qb=client)Date formattingWhen setting date or datetime fields, Quickbooks requires a specific format.
Formating helpers are available in helpers.py. Example usage:date_string=qb_date_format(date(2016,7,22))date_time_string=qb_datetime_format(datetime(2016,7,22,10,35,00))date_time_with_utc_string=qb_datetime_utc_offset_format(datetime(2016,7,22,10,35,00),'-06:00')Exception HandlingThe QuickbooksException object contains additionalQBO error codeinformation.fromquickbooks.exceptionsimportQuickbooksExceptiontry:pass# perform a Quickbooks operationexceptQuickbooksExceptionase:e.message# contains the error message returned from QBOe.error_code# contains thee.detail# contains additional information when availableNote:Objects and object property names match their Quickbooks
counterparts and do not follow PEP8.Note:This is a work-in-progress made public to help other
developers access the QuickBooks API. Built for a Django project.