Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Python library for accessing the Quickbooks API.

License

NotificationsYou must be signed in to change notification settings

pythonthings/python-quickbooks

 
 

Repository files navigation

Build StatusCoverage Status

A Python library for accessing the Quickbooks API. Complete rework ofquickbooks-python.

These instructions were written for a Django application. Make sure tochange it to whatever framework/method you’re using.

Connecting your application to Quickbooks Online

  1. Create the Authorization URL for your application:

    from quickbooks import QuickBooksquickbooks = QuickBooks(    sandbox=True,    consumer_key=QUICKBOOKS_CLIENT_KEY,    consumer_secret=QUICKBOOKS_CLIENT_SECRET,    callback_url=CALLBACK_URL)authorize_url = quickbooks.get_authorize_url()request_token = quickbooks.request_tokenrequest_token_secret = quickbooks.request_token_secret

    Store theauthorize_url,request_token, andrequest_token_secretfor use in the Callback method.

  2. Handle the callback:

    quickbooks = QuickBooks(    sandbox=True,    consumer_key=QUICKBOOKS_CLIENT_KEY,    consumer_secret=QUICKBOOKS_CLIENT_SECRET)quickbooks.authorize_url = authorize_urlquickbooks.request_token = request_tokenquickbooks.request_token_secret = request_token_secretquickbooks.set_up_service()quickbooks.get_access_tokens(request.GET['oauth_verifier'])realm_id = request.GET['realmId']access_token = quickbooks.access_tokenaccess_token_secret = quickbooks.access_token_secret

    Storerealm_id,access_token, andaccess_token_secret for later use.

Accessing the API

QuickBooks client uses a singleton pattern. Just be sure to create theQuickBooks object before you make any calls to QBO. Setup the clientconnection using the storedaccess_token and theaccess_token_secret andrealm_id:

from quickbooks import QuickBooksQuickBooks(    sandbox=True,    consumer_key=QUICKBOOKS_CLIENT_KEY,    consumer_secret=QUICKBOOKS_CLIENT_SECRET,    access_token=access_token,    access_token_secret=access_token_secret,    company_id=realm_id)

If you need to access a minor version (SeeMinor versions fordetails) pass in minorversion when setting up the client:

QuickBooks(    sandbox=True,    consumer_key=QUICKBOOKS_CLIENT_KEY,    consumer_secret=QUICKBOOKS_CLIENT_SECRET,    access_token=access_token,    access_token_secret=access_token_secret,    company_id=realm_id,    minorversion=4)

List of objects:

from quickbooks.objects.customerimport Customer customers = Customer.all()

Note: The maximum number of entities that can be returned in aresponse is 1000. If the result size is not specified, the defaultnumber is 100. (SeeIntuit developer guide for details)

Filtered list of objects:

customers = Customer.filter(Active=True, FamilyName="Smith")

Filtered list of objects with paging:

customers = Customer.filter(start_position=1, max_results=25, Active=True, FamilyName="Smith")

List Filtered by values in list:

customer_names = ['Customer1', 'Customer2', 'Customer3']customers = Customer.choose(customer_names, field="DisplayName")

List with custom Where Clause (do not include the “WHERE”):

customers = Customer.where("Active = True AND CompanyName LIKE 'S%'")

List with custom Where Clause and paging:

customers = Customer.where("CompanyName LIKE 'S%'", start_position=1, max_results=25)

Filtering a list with a custom query (SeeIntuit developer guide forsupported SQL statements):

customer = Customer.query("SELECT * FROM Customer WHERE Active = True")

Filtering a list with a custom query with paging:

customer = Customer.query("SELECT * FROM Customer WHERE Active = True STARTPOSITION 1 MAXRESULTS 25")

Get single object by Id and update:

customer = Customer.get(1)customer.CompanyName = "New Test Company Name"customer.save()

Create new object:

customer = Customer()customer.CompanyName = "Test Company"customer.save()

Batch Operations

The batch operation enables an application to perform multipleoperations in a single request (SeeIntuit Batch Operations Guide forfull details).

Batch create a list of objects:

from quickbooks.batch import batch_createcustomer1 = Customer()customer1.CompanyName = "Test Company 1"customer1.save()customer2 = Customer()customer2.CompanyName = "Test Company 2"customer2.save()customers = []customers.append(customer1)customers.append(customer2)results = batch_create(customers)

Batch update a list of objects:

from quickbooks.batch import batch_updatecustomers = Customer.filter(Active=True)# Update customer recordsresults = batch_update(customers)

Batch delete a list of objects:

from quickbooks.batch import batch_deletecustomers = Customer.filter(Active=False)results = batch_delete(customers)Batch delete a list of objects:
from quickbooks.batch import batch_deletecustomers = Customer.filter(Active=False)results = batch_delete(customers)

Review results for batch operation:

# successes is a list of objects that were successfully updatedfor obj in results.successes:    print "Updated " + obj.DisplayName# faults contains list of failed operations and associated errorsfor fault in results.faults:    print "Operation failed on " + fault.original_object.DisplayName    for error in fault.Error:        print "Error " + error.Message

Note: Objects and object property names match their Quickbookscounterparts and do not follow PEP8.

Note: This is a work-in-progress made public to help otherdevelopers access the QuickBooks API. Built for a Django project runningon Python 2.

About

A Python library for accessing the Quickbooks API.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python100.0%

[8]ページ先頭

©2009-2025 Movatter.jp