@@ -20,53 +20,54 @@ With quickbooks-cli
20
20
-------------------
21
21
22
22
::
23
+
23
24
quickbooks-cli [-h] [-s] [-p PORT] consumer_key consumer_secret
24
25
25
26
Manually
26
27
--------
27
28
28
29
1. Create the Authorization URL for your application:
29
30
30
- ::
31
+ .. code-block :: python
31
32
32
- from quickbooks import QuickBooks
33
+ from quickbooks import QuickBooks
33
34
34
- client = QuickBooks(
35
- sandbox=True,
36
- consumer_key=QUICKBOOKS_CLIENT_KEY,
37
- consumer_secret=QUICKBOOKS_CLIENT_SECRET,
38
- callback_url=CALLBACK_URL
39
- )
35
+ client = QuickBooks(
36
+ sandbox = True ,
37
+ consumer_key = QUICKBOOKS_CLIENT_KEY ,
38
+ consumer_secret = QUICKBOOKS_CLIENT_SECRET ,
39
+ callback_url = CALLBACK_URL
40
+ )
40
41
41
- authorize_url = client.get_authorize_url()
42
- request_token = client.request_token
43
- request_token_secret = client.request_token_secret
42
+ authorize_url = client.get_authorize_url()
43
+ request_token = client.request_token
44
+ request_token_secret = client.request_token_secret
44
45
45
- Store the ``authorize_url ``, ``request_token ``, and ``request_token_secret ``
46
- for use in the Callback method.
46
+ Store the ``authorize_url ``, ``request_token ``, and ``request_token_secret ``
47
+ for use in the Callback method.
47
48
48
49
2. Handle the callback:
49
50
50
- ::
51
+ .. code-block :: python
51
52
52
- client = QuickBooks(
53
- sandbox=True,
54
- consumer_key=QUICKBOOKS_CLIENT_KEY,
55
- consumer_secret=QUICKBOOKS_CLIENT_SECRET
56
- )
53
+ client = QuickBooks(
54
+ sandbox = True ,
55
+ consumer_key = QUICKBOOKS_CLIENT_KEY ,
56
+ consumer_secret = QUICKBOOKS_CLIENT_SECRET
57
+ )
57
58
58
- client.authorize_url = authorize_url
59
- client.request_token = request_token
60
- client.request_token_secret = request_token_secret
61
- client.set_up_service()
59
+ client.authorize_url = authorize_url
60
+ client.request_token = request_token
61
+ client.request_token_secret = request_token_secret
62
+ client.set_up_service()
62
63
63
- client.get_access_tokens(request.GET['oauth_verifier'])
64
+ client.get_access_tokens(request.GET [' oauth_verifier' ])
64
65
65
- realm_id = request.GET['realmId']
66
- access_token = client.access_token
67
- access_token_secret = client.access_token_secret
66
+ realm_id = request.GET [' realmId' ]
67
+ access_token = client.access_token
68
+ access_token_secret = client.access_token_secret
68
69
69
- Store ``realm_id ``, ``access_token ``, and ``access_token_secret `` for later use.
70
+ Store ``realm_id ``, ``access_token ``, and ``access_token_secret `` for later use.
70
71
71
72
Accessing the API
72
73
-----------------
@@ -75,9 +76,9 @@ Create the QuickBooks client object before you make any calls to QBO. Setup the
75
76
connection using the stored ``access_token `` and the
76
77
``access_token_secret `` and ``realm_id ``:
77
78
78
- ::
79
+ .. code-block :: python
79
80
80
- from quickbooks import QuickBooks
81
+ from quickbooks import QuickBooks
81
82
82
83
client = QuickBooks(
83
84
sandbox = True ,
@@ -91,7 +92,7 @@ connection using the stored ``access_token`` and the
91
92
If you need to access a minor version (See `Minor versions `_ for
92
93
details) pass in minorversion when setting up the client:
93
94
94
- ::
95
+ .. code-block :: python
95
96
96
97
client = QuickBooks(
97
98
sandbox = True ,
@@ -105,90 +106,89 @@ details) pass in minorversion when setting up the client:
105
106
106
107
You can disconnect the current Quickbooks Account like so (See `Disconnect documentation `_ for full details):
107
108
108
- ::
109
+ .. code-block :: python
109
110
110
- client.disconnect_account()
111
+ client.disconnect_account()
111
112
112
113
If your consumer_key never changes you can enable the client to stay running:
113
114
114
- ::
115
+ .. code-block :: python
115
116
116
- QuickBooks.enable_global()
117
+ QuickBooks.enable_global()
117
118
118
119
You can disable the global client like so:
119
120
120
- ::
121
+ .. code-block :: python
121
122
122
- QuickBooks.disable_global()
123
+ QuickBooks.disable_global()
123
124
124
125
125
126
List of objects:
126
127
127
- ::
128
-
128
+ .. code-block :: python
129
129
130
- from quickbooks.objects.customer
131
- import Customer customers = Customer.all(qb=client)
130
+ from quickbooks.objects.customer import Customer
131
+ customers = Customer.all(qb = client)
132
132
133
133
**Note: ** The maximum number of entities that can be returned in a
134
134
response is 1000. If the result size is not specified, the default
135
135
number is 100. (See `Intuit developer guide `_ for details)
136
136
137
137
Filtered list of objects:
138
138
139
- ::
139
+ .. code-block :: python
140
140
141
141
customers = Customer.filter(Active = True , FamilyName = " Smith" , qb = client)
142
142
143
143
Filtered list of objects with paging:
144
144
145
- ::
145
+ .. code-block :: python
146
146
147
147
customers = Customer.filter(start_position = 1 , max_results = 25 , Active = True , FamilyName = " Smith" , qb = client)
148
148
149
149
List Filtered by values in list:
150
150
151
- ::
151
+ .. code-block :: python
152
152
153
153
customer_names = [' Customer1' , ' Customer2' , ' Customer3' ]
154
154
customers = Customer.choose(customer_names, field = " DisplayName" , qb = client)
155
155
156
- List with custom Where Clause (do not include the “ WHERE” ):
156
+ List with custom Where Clause (do not include the `` " WHERE" `` ):
157
157
158
- ::
158
+ .. code-block :: python
159
159
160
160
customers = Customer.where(" Active = True AND CompanyName LIKE 'S%'" , qb = client)
161
161
162
162
List with custom Where Clause and paging:
163
163
164
- ::
164
+ .. code-block :: python
165
165
166
166
customers = Customer.where(" CompanyName LIKE 'S%'" , start_position = 1 , max_results = 25 , qb = client)
167
167
168
168
Filtering a list with a custom query (See `Intuit developer guide `_ for
169
169
supported SQL statements):
170
170
171
- ::
171
+ .. code-block :: python
172
172
173
- customer = Customer.query("SELECT * FROM Customer WHERE Active = True", qb=client)
173
+ customers = Customer.query(" SELECT * FROM Customer WHERE Active = True" , qb = client)
174
174
175
175
Filtering a list with a custom query with paging:
176
176
177
- ::
177
+ .. code-block :: python
178
178
179
- customer = Customer.query("SELECT * FROM Customer WHERE Active = True STARTPOSITION 1 MAXRESULTS 25", qb=client)
179
+ customers = Customer.query(" SELECT * FROM Customer WHERE Active = True STARTPOSITION 1 MAXRESULTS 25" , qb = client)
180
180
181
181
Get single object by Id and update:
182
182
183
- ::
183
+ .. code-block :: python
184
184
185
185
customer = Customer.get(1 , qb = client)
186
186
customer.CompanyName = " New Test Company Name"
187
187
customer.save(qb = client)
188
188
189
189
Create new object:
190
190
191
- ::
191
+ .. code-block :: python
192
192
193
193
customer = Customer()
194
194
customer.CompanyName = " Test Company"
@@ -203,7 +203,7 @@ full details).
203
203
204
204
Batch create a list of objects:
205
205
206
- ::
206
+ .. code-block :: python
207
207
208
208
from quickbooks.batch import batch_create
209
209
@@ -221,58 +221,57 @@ Batch create a list of objects:
221
221
222
222
Batch update a list of objects:
223
223
224
- ::
224
+ .. code-block :: python
225
225
226
- from quickbooks.batch import batch_update
226
+ from quickbooks.batch import batch_update
227
227
228
- customers = Customer.filter(Active=True)
228
+ customers = Customer.filter(Active = True )
229
229
230
- # Update customer records
230
+ # Update customer records
231
231
232
- results = batch_update(customers, qb=client)
232
+ results = batch_update(customers, qb = client)
233
233
234
234
Batch delete a list of objects:
235
235
236
- ::
237
-
238
- from quickbooks.batch import batch_delete
236
+ .. code-block :: python
239
237
240
- customers = Customer.filter(Active=False)
241
- results = batch_delete(customers, qb=client)
238
+ from quickbooks.batch import batch_delete
242
239
240
+ customers = Customer.filter(Active = False )
241
+ results = batch_delete(customers, qb = client)
243
242
244
243
Review results for batch operation:
245
244
246
- ::
245
+ .. code-block :: python
247
246
248
- # successes is a list of objects that were successfully updated
249
- for obj in results.successes:
250
- print "Updated " + obj.DisplayName
247
+ # successes is a list of objects that were successfully updated
248
+ for obj in results.successes:
249
+ print " Updated " + obj.DisplayName
251
250
252
- # faults contains list of failed operations and associated errors
253
- for fault in results.faults:
254
- print "Operation failed on " + fault.original_object.DisplayName
255
-
256
- for error in fault.Error:
257
- print "Error " + error.Message
251
+ # faults contains list of failed operations and associated errors
252
+ for fault in results.faults:
253
+ print " Operation failed on " + fault.original_object.DisplayName
254
+
255
+ for error in fault.Error:
256
+ print " Error " + error.Message
258
257
259
258
Change Data Capture
260
259
-----------------------
261
260
Change Data Capture returns a list of objects that have changed since a given time (see `Change data capture `_ for more
262
261
details):
263
262
264
- ::
263
+ .. code-block :: python
265
264
266
265
from quickbooks.cdc import change_data_capture
267
266
from quickbooks.objects import Invoice
268
267
269
268
cdc_response = change_data_capture([Invoice], " 2017-01-01T00:00:00" , qb = client)
270
269
for invoice in cdc_response.Invoice:
271
- # Do something with the invoice
270
+ # Do something with the invoice
272
271
273
272
Querying muliple entity types at the same time:
274
273
275
- ::
274
+ .. code-block :: python
276
275
277
276
from quickbooks.objects import Invoice, Customer
278
277
@@ -281,63 +280,60 @@ Querying muliple entity types at the same time:
281
280
282
281
If you use a ``datetime `` object for the timestamp, it is automatically converted to a string:
283
282
284
- ::
283
+ .. code-block :: python
285
284
286
285
from datetime import datetime
287
286
288
287
cdc_response = change_data_capture([Invoice, Customer], datetime(2017 , 1 , 1 , 0 , 0 , 0 ), qb = client)
289
288
290
-
291
289
Attachments
292
290
----------------
293
291
See `Attachable documentation `_ for list of valid file types, file size limits and other restrictions.
294
292
295
293
Attaching a note to a customer:
296
294
297
- ::
295
+ .. code-block :: python
298
296
299
- attachment = Attachable()
297
+ attachment = Attachable()
300
298
301
- attachable_ref = AttachableRef()
302
- attachable_ref.EntityRef = customer.to_ref()
299
+ attachable_ref = AttachableRef()
300
+ attachable_ref.EntityRef = customer.to_ref()
303
301
304
- attachment.AttachableRef.append(attachable_ref)
302
+ attachment.AttachableRef.append(attachable_ref)
305
303
306
- attachment.Note = 'This is a note'
307
- attachment.save(qb=client)
304
+ attachment.Note = ' This is a note'
305
+ attachment.save(qb = client)
308
306
309
307
Attaching a file to customer:
310
308
311
- ::
312
-
313
- attachment = Attachable()
314
-
315
- attachable_ref = AttachableRef()
316
- attachable_ref.EntityRef = customer.to_ref()
309
+ .. code-block :: python
317
310
318
- attachment.AttachableRef.append(attachable_ref )
311
+ attachment = Attachable( )
319
312
320
- attachment.FileName = 'Filename'
321
- attachment._FilePath = '/folder/filename' # full path to file
322
- attachment.ContentType = 'application/pdf'
323
- attachment.save(qb=client)
313
+ attachable_ref = AttachableRef()
314
+ attachable_ref.EntityRef = customer.to_ref()
324
315
316
+ attachment.AttachableRef.append(attachable_ref)
325
317
318
+ attachment.FileName = ' Filename'
319
+ attachment._FilePath = ' /folder/filename' # full path to file
320
+ attachment.ContentType = ' application/pdf'
321
+ attachment.save(qb = client)
326
322
327
323
Working with JSON data
328
324
----------------
329
325
All objects include ``to_json `` and ``from_json `` methods.
330
326
331
327
Converting an object to JSON data:
332
328
333
- ::
329
+ .. code-block :: python
334
330
335
331
account = Account.get(1 , qb = client)
336
332
json_data = account.to_json()
337
333
338
334
Loading JSON data into a quickbooks object:
339
335
340
- ::
336
+ .. code-block :: python
341
337
342
338
account = Account()
343
339
account.from_json(
@@ -353,7 +349,7 @@ Date formatting
353
349
When setting date or datetime fields, Quickbooks requires a specific format.
354
350
Formating helpers are available in helpers.py. Example usage:
355
351
356
- ::
352
+ .. code-block :: python
357
353
358
354
date_string = qb_date_format(date(2016 , 7 , 22 ))
359
355
date_time_string = qb_datetime_format(datetime(2016 , 7 , 22 , 10 , 35 , 00 ))
0 commit comments