@@ -58,16 +58,15 @@ Connecting your application to Quickbooks Online
5858Accessing the API
5959-----------------
6060
61- QuickBooks client uses a singleton pattern. Just be sure to create the
62- QuickBooks object before you make any calls to QBO. Setup the client
61+ Create the QuickBooks client object before you make any calls to QBO. Setup the client
6362connection using the stored ``access_token `` and the
6463``access_token_secret `` and ``realm_id ``:
6564
6665::
6766
6867 from quickbooks import QuickBooks
6968
70- QuickBooks(
69+ client = QuickBooks(
7170 sandbox=True,
7271 consumer_key=QUICKBOOKS_CLIENT_KEY,
7372 consumer_secret=QUICKBOOKS_CLIENT_SECRET,
@@ -81,7 +80,7 @@ details) pass in minorversion when setting up the client:
8180
8281::
8382
84- QuickBooks(
83+ client = QuickBooks(
8584 sandbox=True,
8685 consumer_key=QUICKBOOKS_CLIENT_KEY,
8786 consumer_secret=QUICKBOOKS_CLIENT_SECRET,
@@ -91,13 +90,19 @@ details) pass in minorversion when setting up the client:
9190 minorversion=4
9291 )
9392
93+ If your consumer_key never changes you can enable the client to stay running:
94+
95+ ::
96+
97+ QuickBooks.enable_global()
98+
9499List of objects:
95100
96101::
97102
98103
99104 from quickbooks.objects.customer
100- import Customer customers = Customer.all()
105+ import Customer customers = Customer.all(qb=client )
101106
102107**Note: ** The maximum number of entities that can be returned in a
103108response is 1000. If the result size is not specified, the default
@@ -107,61 +112,61 @@ Filtered list of objects:
107112
108113::
109114
110- customers = Customer.filter(Active=True, FamilyName="Smith")
115+ customers = Customer.filter(Active=True, FamilyName="Smith", qb=client )
111116
112117Filtered list of objects with paging:
113118
114119::
115120
116- customers = Customer.filter(start_position=1, max_results=25, Active=True, FamilyName="Smith")
121+ customers = Customer.filter(start_position=1, max_results=25, Active=True, FamilyName="Smith", qb=client )
117122
118123List Filtered by values in list:
119124
120125::
121126
122127 customer_names = ['Customer1', 'Customer2', 'Customer3']
123- customers = Customer.choose(customer_names, field="DisplayName")
128+ customers = Customer.choose(customer_names, field="DisplayName", qb=client )
124129
125130List with custom Where Clause (do not include the “WHERE”):
126131
127132::
128133
129- customers = Customer.where("Active = True AND CompanyName LIKE 'S%'")
134+ customers = Customer.where("Active = True AND CompanyName LIKE 'S%'", qb=client )
130135
131136List with custom Where Clause and paging:
132137
133138::
134139
135- customers = Customer.where("CompanyName LIKE 'S%'", start_position=1, max_results=25)
140+ customers = Customer.where("CompanyName LIKE 'S%'", start_position=1, max_results=25, qb=client )
136141
137142Filtering a list with a custom query (See `Intuit developer guide `_ for
138143supported SQL statements):
139144
140145::
141146
142- customer = Customer.query("SELECT * FROM Customer WHERE Active = True")
147+ customer = Customer.query("SELECT * FROM Customer WHERE Active = True", qb=client )
143148
144149Filtering a list with a custom query with paging:
145150
146151::
147152
148- customer = Customer.query("SELECT * FROM Customer WHERE Active = True STARTPOSITION 1 MAXRESULTS 25")
153+ customer = Customer.query("SELECT * FROM Customer WHERE Active = True STARTPOSITION 1 MAXRESULTS 25", qb=client )
149154
150155Get single object by Id and update:
151156
152157::
153158
154- customer = Customer.get(1)
159+ customer = Customer.get(1, qb=client )
155160 customer.CompanyName = "New Test Company Name"
156- customer.save()
161+ customer.save(qb=client )
157162
158163Create new object:
159164
160165::
161166
162167 customer = Customer()
163168 customer.CompanyName = "Test Company"
164- customer.save()
169+ customer.save(qb=client )
165170
166171Batch Operations
167172----------------
@@ -178,17 +183,15 @@ Batch create a list of objects:
178183
179184 customer1 = Customer()
180185 customer1.CompanyName = "Test Company 1"
181- customer1.save()
182186
183187 customer2 = Customer()
184188 customer2.CompanyName = "Test Company 2"
185- customer2.save()
186189
187190 customers = []
188191 customers.append(customer1)
189192 customers.append(customer2)
190193
191- results = batch_create(customers)
194+ results = batch_create(customers, qb=client )
192195
193196Batch update a list of objects:
194197
@@ -200,7 +203,7 @@ Batch update a list of objects:
200203
201204 # Update customer records
202205
203- results = batch_update(customers)
206+ results = batch_update(customers, qb=client )
204207
205208Batch delete a list of objects:
206209
@@ -209,16 +212,8 @@ Batch delete a list of objects:
209212 from quickbooks.batch import batch_delete
210213
211214 customers = Customer.filter(Active=False)
212- results = batch_delete(customers)
213-
214- Batch delete a list of objects:
215+ results = batch_delete(customers, qb=client)
215216
216- ::
217-
218- from quickbooks.batch import batch_delete
219-
220- customers = Customer.filter(Active=False)
221- results = batch_delete(customers)
222217
223218Review results for batch operation:
224219
0 commit comments