-
Notifications
You must be signed in to change notification settings - Fork 237
/
index.js
2723 lines (2469 loc) · 102 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @file Node.js client for QuickBooks V3 API
* @name node-quickbooks
* @author Michael Cohen <[email protected]>
* @license ISC
* @copyright 2014 Michael Cohen
*/
var request = require('request'),
uuid = require('uuid'),
debug = require('request-debug'),
util = require('util'),
formatISO = require('date-fns/fp/formatISO'),
_ = require('underscore'),
Promise = require('bluebird'),
version = require('./package.json').version,
xmlParser = new (require('fast-xml-parser').XMLParser)();
module.exports = QuickBooks
QuickBooks.APP_CENTER_BASE = 'https://appcenter.intuit.com';
QuickBooks.V3_ENDPOINT_BASE_URL = 'https://sandbox-quickbooks.api.intuit.com/v3/company/';
QuickBooks.QUERY_OPERATORS = ['=', 'IN', '<', '>', '<=', '>=', 'LIKE'];
QuickBooks.TOKEN_URL = 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer';
QuickBooks.REVOKE_URL = 'https://developer.api.intuit.com/v2/oauth2/tokens/revoke';
var OAUTH_ENDPOINTS = {
'1.0a': function (callback) {
callback({
REQUEST_TOKEN_URL: 'https://oauth.intuit.com/oauth/v1/get_request_token',
ACCESS_TOKEN_URL: 'https://oauth.intuit.com/oauth/v1/get_access_token',
APP_CENTER_URL: QuickBooks.APP_CENTER_BASE + '/Connect/Begin?oauth_token=',
RECONNECT_URL: QuickBooks.APP_CENTER_BASE + '/api/v1/connection/reconnect',
DISCONNECT_URL: QuickBooks.APP_CENTER_BASE + '/api/v1/connection/disconnect'
});
},
'2.0': function (callback, discoveryUrl) {
var NEW_ENDPOINT_CONFIGURATION = {};
request({
url: discoveryUrl,
headers: {
Accept: 'application/json'
}
}, function (err, res) {
if (err) {
console.log(err);
return err;
}
var json;
try {
json = JSON.parse(res.body);
} catch (error) {
console.log(error);
return error;
}
NEW_ENDPOINT_CONFIGURATION.AUTHORIZATION_URL = json.authorization_endpoint;;
NEW_ENDPOINT_CONFIGURATION.TOKEN_URL = json.token_endpoint;
NEW_ENDPOINT_CONFIGURATION.USER_INFO_URL = json.userinfo_endpoint;
NEW_ENDPOINT_CONFIGURATION.REVOKE_URL = json.revocation_endpoint;
callback(NEW_ENDPOINT_CONFIGURATION);
});
}
};
OAUTH_ENDPOINTS['1.0'] = OAUTH_ENDPOINTS['1.0a'];
/**
* Sets endpoints per OAuth version
*
* @param version - 1.0 for OAuth 1.0a, 2.0 for OAuth 2.0
* @param useSandbox - true to use the OAuth 2.0 sandbox discovery document, false (or unspecified, for backward compatibility) to use the prod discovery document.
*/
QuickBooks.setOauthVersion = function (version, useSandbox) {
version = (typeof version === 'number') ? version.toFixed(1) : version;
QuickBooks.version = version;
var discoveryUrl = useSandbox ? 'https://developer.intuit.com/.well-known/openid_sandbox_configuration/' : 'https://developer.api.intuit.com/.well-known/openid_configuration/';
OAUTH_ENDPOINTS[version](function (endpoints) {
for (var k in endpoints) {
QuickBooks[k] = endpoints[k];
}
}, discoveryUrl);
};
QuickBooks.setOauthVersion('1.0');
/**
* Node.js client encapsulating access to the QuickBooks V3 Rest API. An instance
* of this class should be instantiated on behalf of each user accessing the api.
*
* @param consumerKey - application key
* @param consumerSecret - application password
* @param token - the OAuth generated user-specific key
* @param tokenSecret - the OAuth generated user-specific password
* @param realmId - QuickBooks companyId, returned as a request parameter when the user is redirected to the provided callback URL following authentication
* @param useSandbox - boolean - See https://developer.intuit.com/v2/blog/2014/10/24/intuit-developer-now-offers-quickbooks-sandboxes
* @param debug - boolean flag to turn on logging of HTTP requests, including headers and body
* @param minorversion - integer to set minorversion in request
* @constructor
*/
function QuickBooks(consumerKey, consumerSecret, token, tokenSecret, realmId, useSandbox, debug, minorversion, oauthversion, refreshToken) {
var prefix = _.isObject(consumerKey) ? 'consumerKey.' : '';
this.consumerKey = eval(prefix + 'consumerKey');
this.consumerSecret = eval(prefix + 'consumerSecret');
this.token = eval(prefix + 'token');
this.tokenSecret = eval(prefix + 'tokenSecret');
this.realmId = eval(prefix + 'realmId');
this.useSandbox = eval(prefix + 'useSandbox');
this.debug = eval(prefix + 'debug');
this.endpoint = this.useSandbox
? QuickBooks.V3_ENDPOINT_BASE_URL
: QuickBooks.V3_ENDPOINT_BASE_URL.replace('sandbox-', '');
this.minorversion = eval(prefix + 'minorversion') || 65;
this.oauthversion = eval(prefix + 'oauthversion') || '1.0a';
this.refreshToken = eval(prefix + 'refreshToken') || null;
if (!eval(prefix + 'tokenSecret') && this.oauthversion !== '2.0') {
throw new Error('tokenSecret not defined');
}
}
/**
*
* Use the refresh token to obtain a new access token.
*
*
*/
QuickBooks.prototype.refreshAccessToken = function(callback) {
var auth = (Buffer.from(this.consumerKey + ':' + this.consumerSecret).toString('base64'));
var postBody = {
url: QuickBooks.TOKEN_URL,
headers: {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: 'Basic ' + auth,
},
form: {
grant_type: 'refresh_token',
refresh_token: this.refreshToken
}
};
request.post(postBody, (function (e, r, data) {
if (r && r.body && r.error!=="invalid_grant") {
var refreshResponse = JSON.parse(r.body);
this.refreshToken = refreshResponse.refresh_token;
this.token = refreshResponse.access_token;
if (callback) callback(e, refreshResponse);
} else {
if (callback) callback(e, r, data);
}
}).bind(this));
};
/**
* Use either refresh token or access token to revoke access (OAuth2).
*
* @param useRefresh - boolean - Indicates which token to use: true to use the refresh token, false to use the access token.
* @param {function} callback - Callback function to call with error/response/data results.
*/
QuickBooks.prototype.revokeAccess = function(useRefresh, callback) {
var auth = (Buffer.from(this.consumerKey + ':' + this.consumerSecret).toString('base64'));
var revokeToken = useRefresh ? this.refreshToken : this.token;
var postBody = {
url: QuickBooks.REVOKE_URL,
headers: {
Accept: 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: 'Basic ' + auth,
},
form: {
token: revokeToken
}
};
request.post(postBody, (function(e, r, data) {
if (r && r.statusCode === 200) {
this.refreshToken = null;
this.token = null;
this.realmId = null;
}
if (callback) callback(e, r, data);
}).bind(this));
};
/**
* Get user info (OAuth2).
*
* @param {function} callback - Callback function to call with error/response/data results.
*/
QuickBooks.prototype.getUserInfo = function(callback) {
module.request(this, 'get', {url: QuickBooks.USER_INFO_URL}, null, callback);
};
/**
* Batch operation to enable an application to perform multiple operations in a single request.
* The following batch items are supported:
create
update
delete
query
* The maximum number of batch items in a single request is 30.
*
* @param {object} items - JavaScript array of batch items
* @param {function} callback - Callback function which is called with any error and list of BatchItemResponses
*/
QuickBooks.prototype.batch = function(items, callback) {
module.request(this, 'post', {url: '/batch'}, {BatchItemRequest: items}, callback)
}
/**
* The change data capture (CDC) operation returns a list of entities that have changed since a specified time.
*
* @param {object} entities - Comma separated list or JavaScript array of entities to search for changes
* @param {object} since - JavaScript Date or string representation of the form '2012-07-20T22:25:51-07:00' to look back for changes until
* @param {function} callback - Callback function which is called with any error and list of changes
*/
QuickBooks.prototype.changeDataCapture = function(entities, since, callback) {
var url = '/cdc?entities='
url += typeof entities === 'string' ? entities : entities.join(',')
url += '&changedSince='
url += typeof since === 'string' ? since : formatISO(since)
module.request(this, 'get', {url: url}, null, callback)
}
/**
* Uploads a file as an Attachable in QBO, optionally linking it to the specified
* QBO Entity.
*
* @param {string} filename - the name of the file
* @param {string} contentType - the mime type of the file
* @param {object} stream - ReadableStream of file contents
* @param {object} entityType - optional string name of the QBO entity the Attachable will be linked to (e.g. Invoice)
* @param {object} entityId - optional Id of the QBO entity the Attachable will be linked to
* @param {function} callback - callback which receives the newly created Attachable
*/
QuickBooks.prototype.upload = function(filename, contentType, stream, entityType, entityId, callback) {
var that = this
var opts = {
url: '/upload',
formData: {
file_content_01: {
value: stream,
options: {
filename: filename,
contentType: contentType
}
}
}
}
module.request(this, 'post', opts, null, module.unwrap(function(err, data) {
if (err || data[0].Fault) {
(callback || entityType)(err || data[0], null)
} else if (_.isFunction(entityType)) {
entityType(null, data[0].Attachable)
} else {
var id = data[0].Attachable.Id
that.updateAttachable({
Id: id,
SyncToken: '0',
AttachableRef: [{
EntityRef: {
type: entityType,
value: entityId + ''
}
}]
}, function(err, data) {
callback(err, data)
})
}
}, 'AttachableResponse'))
}
/**
* Creates the Account in QuickBooks
*
* @param {object} account - The unsaved account, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Account
*/
QuickBooks.prototype.createAccount = function(account, callback) {
module.create(this, 'account', account, callback)
}
/**
* Creates the Attachable in QuickBooks
*
* @param {object} attachable - The unsaved attachable, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Attachable
*/
QuickBooks.prototype.createAttachable = function(attachable, callback) {
module.create(this, 'attachable', attachable, callback)
}
/**
* Creates the Bill in QuickBooks
*
* @param {object} bill - The unsaved bill, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Bill
*/
QuickBooks.prototype.createBill = function(bill, callback) {
module.create(this, 'bill', bill, callback)
}
/**
* Creates the BillPayment in QuickBooks
*
* @param {object} billPayment - The unsaved billPayment, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent BillPayment
*/
QuickBooks.prototype.createBillPayment = function(billPayment, callback) {
module.create(this, 'billPayment', billPayment, callback)
}
/**
* Creates the Class in QuickBooks
*
* @param {object} class - The unsaved class, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Class
*/
QuickBooks.prototype.createClass = function(klass, callback) {
module.create(this, 'class', klass, callback)
}
/**
* Creates the CreditMemo in QuickBooks
*
* @param {object} creditMemo - The unsaved creditMemo, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent CreditMemo
*/
QuickBooks.prototype.createCreditMemo = function(creditMemo, callback) {
module.create(this, 'creditMemo', creditMemo, callback)
}
/**
* Creates the Customer in QuickBooks
*
* @param {object} customer - The unsaved customer, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Customer
*/
QuickBooks.prototype.createCustomer = function(customer, callback) {
module.create(this, 'customer', customer, callback)
}
/**
* Creates the Department in QuickBooks
*
* @param {object} department - The unsaved department, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Department
*/
QuickBooks.prototype.createDepartment = function(department, callback) {
module.create(this, 'department', department, callback)
}
/**
* Creates the Deposit in QuickBooks
*
* @param {object} deposit - The unsaved Deposit, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Deposit
*/
QuickBooks.prototype.createDeposit = function(deposit, callback) {
module.create(this, 'deposit', deposit, callback)
}
/**
* Creates the Employee in QuickBooks
*
* @param {object} employee - The unsaved employee, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Employee
*/
QuickBooks.prototype.createEmployee = function(employee, callback) {
module.create(this, 'employee', employee, callback)
}
/**
* Creates the Estimate in QuickBooks
*
* @param {object} estimate - The unsaved estimate, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Estimate
*/
QuickBooks.prototype.createEstimate = function(estimate, callback) {
module.create(this, 'estimate', estimate, callback)
}
/**
* Creates the Invoice in QuickBooks
*
* @param {object} invoice - The unsaved invoice, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Invoice
*/
QuickBooks.prototype.createInvoice = function(invoice, callback) {
module.create(this, 'invoice', invoice, callback)
}
/**
* Creates the Item in QuickBooks
*
* @param {object} item - The unsaved item, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Item
*/
QuickBooks.prototype.createItem = function(item, callback) {
module.create(this, 'item', item, callback)
}
/**
* Creates the JournalCode in QuickBooks
*
* @param {object} journalCode - The unsaved journalCode, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent JournalCode
*/
QuickBooks.prototype.createJournalCode = function(journalCode, callback) {
module.create(this, 'journalCode', journalCode, callback)
}
/**
* Creates the JournalEntry in QuickBooks
*
* @param {object} journalEntry - The unsaved journalEntry, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent JournalEntry
*/
QuickBooks.prototype.createJournalEntry = function(journalEntry, callback) {
module.create(this, 'journalEntry', journalEntry, callback)
}
/**
* Creates the Payment in QuickBooks
*
* @param {object} payment - The unsaved payment, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Payment
*/
QuickBooks.prototype.createPayment = function(payment, callback) {
module.create(this, 'payment', payment, callback)
}
/**
* Creates the PaymentMethod in QuickBooks
*
* @param {object} paymentMethod - The unsaved paymentMethod, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent PaymentMethod
*/
QuickBooks.prototype.createPaymentMethod = function(paymentMethod, callback) {
module.create(this, 'paymentMethod', paymentMethod, callback)
}
/**
* Creates the Purchase in QuickBooks
*
* @param {object} purchase - The unsaved purchase, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Purchase
*/
QuickBooks.prototype.createPurchase = function(purchase, callback) {
module.create(this, 'purchase', purchase, callback)
}
/**
* Creates the PurchaseOrder in QuickBooks
*
* @param {object} purchaseOrder - The unsaved purchaseOrder, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent PurchaseOrder
*/
QuickBooks.prototype.createPurchaseOrder = function(purchaseOrder, callback) {
module.create(this, 'purchaseOrder', purchaseOrder, callback)
}
/**
* Creates the RefundReceipt in QuickBooks
*
* @param {object} refundReceipt - The unsaved refundReceipt, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent RefundReceipt
*/
QuickBooks.prototype.createRefundReceipt = function(refundReceipt, callback) {
module.create(this, 'refundReceipt', refundReceipt, callback)
}
/**
* Creates the SalesReceipt in QuickBooks
*
* @param {object} salesReceipt - The unsaved salesReceipt, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent SalesReceipt
*/
QuickBooks.prototype.createSalesReceipt = function(salesReceipt, callback) {
module.create(this, 'salesReceipt', salesReceipt, callback)
}
/**
* Creates the TaxAgency in QuickBooks
*
* @param {object} taxAgency - The unsaved taxAgency, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent TaxAgency
*/
QuickBooks.prototype.createTaxAgency = function(taxAgency, callback) {
module.create(this, 'taxAgency', taxAgency, callback)
}
/**
* Creates the TaxService in QuickBooks
*
* @param {object} taxService - The unsaved taxService, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent TaxService
*/
QuickBooks.prototype.createTaxService = function(taxService, callback) {
module.create(this, 'taxService/taxcode', taxService, callback)
}
/**
* Creates the Term in QuickBooks
*
* @param {object} term - The unsaved term, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Term
*/
QuickBooks.prototype.createTerm = function(term, callback) {
module.create(this, 'term', term, callback)
}
/**
* Creates the TimeActivity in QuickBooks
*
* @param {object} timeActivity - The unsaved timeActivity, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent TimeActivity
*/
QuickBooks.prototype.createTimeActivity = function(timeActivity, callback) {
module.create(this, 'timeActivity', timeActivity, callback)
}
/**
* Creates the Transfer in QuickBooks
*
* @param {object} transfer - The unsaved Transfer, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Transfer
*/
QuickBooks.prototype.createTransfer = function(transfer, callback) {
module.create(this, 'transfer', transfer, callback)
}
/**
* Creates the Vendor in QuickBooks
*
* @param {object} vendor - The unsaved vendor, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent Vendor
*/
QuickBooks.prototype.createVendor = function(vendor, callback) {
module.create(this, 'vendor', vendor, callback)
}
/**
* Creates the VendorCredit in QuickBooks
*
* @param {object} vendorCredit - The unsaved vendorCredit, to be persisted in QuickBooks
* @param {function} callback - Callback function which is called with any error and the persistent VendorCredit
*/
QuickBooks.prototype.createVendorCredit = function(vendorCredit, callback) {
module.create(this, 'vendorCredit', vendorCredit, callback)
}
/**
* Retrieves the Account from QuickBooks
*
* @param {string} Id - The Id of persistent Account
* @param {function} callback - Callback function which is called with any error and the persistent Account
*/
QuickBooks.prototype.getAccount = function(id, callback) {
module.read(this, 'account', id, callback)
}
/**
* Retrieves the Attachable from QuickBooks
*
* @param {string} Id - The Id of persistent Attachable
* @param {function} callback - Callback function which is called with any error and the persistent Attachable
*/
QuickBooks.prototype.getAttachable = function(id, callback) {
module.read(this, 'attachable', id, callback)
}
/**
* Retrieves the Bill from QuickBooks
*
* @param {string} Id - The Id of persistent Bill
* @param {function} callback - Callback function which is called with any error and the persistent Bill
*/
QuickBooks.prototype.getBill = function(id, callback) {
module.read(this, 'bill', id, callback)
}
/**
* Retrieves the BillPayment from QuickBooks
*
* @param {string} Id - The Id of persistent BillPayment
* @param {function} callback - Callback function which is called with any error and the persistent BillPayment
*/
QuickBooks.prototype.getBillPayment = function(id, callback) {
module.read(this, 'billPayment', id, callback)
}
/**
* Retrieves the Class from QuickBooks
*
* @param {string} Id - The Id of persistent Class
* @param {function} callback - Callback function which is called with any error and the persistent Class
*/
QuickBooks.prototype.getClass = function(id, callback) {
module.read(this, 'class', id, callback)
}
/**
* Retrieves the CompanyInfo from QuickBooks
*
* @param {string} Id - The Id of persistent CompanyInfo
* @param {function} callback - Callback function which is called with any error and the persistent CompanyInfo
*/
QuickBooks.prototype.getCompanyInfo = function(id, callback) {
module.read(this, 'companyInfo', id, callback)
}
/**
* Retrieves the CompanyCurrency from QuickBooks
*
* @param {string} Id - The Id of persistent CompanyCurrency
* @param {function} callback - Callback function which is called with any error and the persistent CompanyCurrency
*/
QuickBooks.prototype.getCompanyCurrency = function(id, callback) {
module.read(this, 'companyCurrency', id, callback)
}
/**
* Retrieves the CreditMemo from QuickBooks
*
* @param {string} Id - The Id of persistent CreditMemo
* @param {function} callback - Callback function which is called with any error and the persistent CreditMemo
*/
QuickBooks.prototype.getCreditMemo = function(id, callback) {
module.read(this, 'creditMemo', id, callback)
}
/**
* Retrieves the Customer from QuickBooks
*
* @param {string} Id - The Id of persistent Customer
* @param {function} callback - Callback function which is called with any error and the persistent Customer
*/
QuickBooks.prototype.getCustomer = function(id, callback) {
module.read(this, 'customer', id, callback)
}
/**
* Retrieves the CustomerType from QuickBooks
*
* @param {string} Id - The Id of persistent CustomerType
* @param {function} callback - Callback function which is called with any error and the persistent CustomerType
*/
QuickBooks.prototype.getCustomerType = function(id, callback) {
module.read(this, 'customerType', id, callback)
}
/**
* Retrieves the Department from QuickBooks
*
* @param {string} Id - The Id of persistent Department
* @param {function} callback - Callback function which is called with any error and the persistent Department
*/
QuickBooks.prototype.getDepartment = function(id, callback) {
module.read(this, 'department', id, callback)
}
/**
* Retrieves the Deposit from QuickBooks
*
* @param {string} Id - The Id of persistent Deposit
* @param {function} callback - Callback function which is called with any error and the persistent Deposit
*/
QuickBooks.prototype.getDeposit = function(id, callback) {
module.read(this, 'deposit', id, callback)
}
/**
* Retrieves the Employee from QuickBooks
*
* @param {string} Id - The Id of persistent Employee
* @param {function} callback - Callback function which is called with any error and the persistent Employee
*/
QuickBooks.prototype.getEmployee = function(id, callback) {
module.read(this, 'employee', id, callback)
}
/**
* Retrieves the Estimate from QuickBooks
*
* @param {string} Id - The Id of persistent Estimate
* @param {function} callback - Callback function which is called with any error and the persistent Estimate
*/
QuickBooks.prototype.getEstimate = function(id, callback) {
module.read(this, 'estimate', id, callback)
}
/**
* Retrieves an ExchangeRate from QuickBooks
*
* @param {object} options - An object with options including the required `sourcecurrencycode` parameter and optional `asofdate` parameter.
* @param {function} callback - Callback function which is called with any error and the ExchangeRate
*/
QuickBooks.prototype.getExchangeRate = function(options, callback) {
var url = "/exchangerate";
module.request(this, 'get', {url: url, qs: options}, null, callback)
}
/**
* Retrieves the Estimate PDF from QuickBooks
*
* @param {string} Id - The Id of persistent Estimate
* @param {function} callback - Callback function which is called with any error and the Estimate PDF
*/
QuickBooks.prototype.getEstimatePdf = function(id, callback) {
module.read(this, 'Estimate', id + '/pdf', callback)
};
/**
* Emails the Estimate PDF from QuickBooks to the address supplied in Estimate.BillEmail.EmailAddress
* or the specified 'sendTo' address
*
* @param {string} Id - The Id of persistent Estimate
* @param {string} sendTo - optional email address to send the PDF to. If not provided, address supplied in Estimate.BillEmail.EmailAddress will be used
* @param {function} callback - Callback function which is called with any error and the Estimate PDF
*/
QuickBooks.prototype.sendEstimatePdf = function(id, sendTo, callback) {
var path = '/estimate/' + id + '/send'
callback = _.isFunction(sendTo) ? sendTo : callback
if (sendTo && ! _.isFunction(sendTo)) {
path += '?sendTo=' + sendTo
}
module.request(this, 'post', {url: path}, null, module.unwrap(callback, 'Estimate'))
}
/**
* Retrieves the Invoice from QuickBooks
*
* @param {string} Id - The Id of persistent Invoice
* @param {function} callback - Callback function which is called with any error and the persistent Invoice
*/
QuickBooks.prototype.getInvoice = function(id, callback) {
module.read(this, 'invoice', id, callback)
}
/**
* Retrieves the Invoice PDF from QuickBooks
*
* @param {string} Id - The Id of persistent Invoice
* @param {function} callback - Callback function which is called with any error and the Invoice PDF
*/
QuickBooks.prototype.getInvoicePdf = function(id, callback) {
module.read(this, 'Invoice', id + '/pdf', callback)
}
/**
* Emails the Invoice PDF from QuickBooks to the address supplied in Invoice.BillEmail.EmailAddress
* or the specified 'sendTo' address
*
* @param {string} Id - The Id of persistent Invoice
* @param {string} sendTo - optional email address to send the PDF to. If not provided, address supplied in Invoice.BillEmail.EmailAddress will be used
* @param {function} callback - Callback function which is called with any error and the Invoice PDF
*/
QuickBooks.prototype.sendInvoicePdf = function(id, sendTo, callback) {
var path = '/invoice/' + id + '/send'
callback = _.isFunction(sendTo) ? sendTo : callback
if (sendTo && ! _.isFunction(sendTo)) {
path += '?sendTo=' + sendTo
}
module.request(this, 'post', {url: path}, null, module.unwrap(callback, 'Invoice'))
}
/**
* Retrieves the Credit Memo PDF from QuickBooks
*
* @param {string} Id - The Id of persistent Credit Memo
* @param {function} callback - Callback function which is called with any error and the Credit Memo PDF
*/
QuickBooks.prototype.getCreditMemoPdf = function(id, callback) {
module.read(this, 'CreditMemo', id + '/pdf', callback)
}
/**
* Emails the Credit Memo PDF from QuickBooks to the address supplied in CreditMemo.BillEmail.EmailAddress
* or the specified 'sendTo' address
*
* @param {string} Id - The Id of persistent Credit Memo
* @param {string} sendTo - optional email address to send the PDF to. If not provided, address supplied in CreditMemo.BillEmail.EmailAddress will be used
* @param {function} callback - Callback function which is called with any error and the Credit Memo PDF
*/
QuickBooks.prototype.sendCreditMemoPdf = function(id, sendTo, callback) {
var path = '/creditmemo/' + id + '/send'
callback = _.isFunction(sendTo) ? sendTo : callback
if (sendTo && ! _.isFunction(sendTo)) {
path += '?sendTo=' + sendTo
}
module.request(this, 'post', {url: path}, null, module.unwrap(callback, 'CreditMemo'))
}
/**
* Emails the Purchase Order from QuickBooks to the address supplied in PurchaseOrder.POEmail.Address
* or the specified 'sendTo' address
*
* @param {string} Id - The Id of persistent Purchase Order
* @param {string} sendTo - optional email address to send the PDF to. If not provided, address supplied in PurchaseOrder.POEmail.Address will be used
* @param {function} callback - Callback function which is called with any error and the Invoice PDF
*/
QuickBooks.prototype.sendPurchaseOrder = function(id, sendTo, callback) {
var path = '/purchaseorder/' + id + '/send'
callback = _.isFunction(sendTo) ? sendTo : callback
if (sendTo && ! _.isFunction(sendTo)) {
path += '?sendTo=' + sendTo
}
module.request(this, 'post', {url: path}, null, module.unwrap(callback, 'PurchaseOrder'))
}
/**
* Retrieves the Item from QuickBooks
*
* @param {string} Id - The Id of persistent Item
* @param {function} callback - Callback function which is called with any error and the persistent Item
*/
QuickBooks.prototype.getItem = function(id, callback) {
module.read(this, 'item', id, callback)
}
/**
* Retrieves the JournalCode from QuickBooks
*
* @param {string} Id - The Id of persistent JournalCode
* @param {function} callback - Callback function which is called with any error and the persistent JournalCode
*/
QuickBooks.prototype.getJournalCode = function(id, callback) {
module.read(this, 'journalCode', id, callback)
}
/**
* Retrieves the JournalEntry from QuickBooks
*
* @param {string} Id - The Id of persistent JournalEntry
* @param {function} callback - Callback function which is called with any error and the persistent JournalEntry
*/
QuickBooks.prototype.getJournalEntry = function(id, callback) {
module.read(this, 'journalEntry', id, callback)
}
/**
* Retrieves the Payment from QuickBooks
*
* @param {string} Id - The Id of persistent Payment
* @param {function} callback - Callback function which is called with any error and the persistent Payment
*/
QuickBooks.prototype.getPayment = function(id, callback) {
module.read(this, 'payment', id, callback)
}
/**
* Retrieves the PaymentMethod from QuickBooks
*
* @param {string} Id - The Id of persistent PaymentMethod
* @param {function} callback - Callback function which is called with any error and the persistent PaymentMethod
*/
QuickBooks.prototype.getPaymentMethod = function(id, callback) {
module.read(this, 'paymentMethod', id, callback)
}
/**
* Retrieves the Preferences from QuickBooks
*
* @param {function} callback - Callback function which is called with any error and the persistent Preferences
*/
QuickBooks.prototype.getPreferences = function(callback) {
module.read(this, 'preferences', null, callback)
}
/**
* Retrieves the Purchase from QuickBooks
*
* @param {string} Id - The Id of persistent Purchase
* @param {function} callback - Callback function which is called with any error and the persistent Purchase
*/
QuickBooks.prototype.getPurchase = function(id, callback) {
module.read(this, 'purchase', id, callback)
}
/**
* Retrieves the PurchaseOrder from QuickBooks
*
* @param {string} Id - The Id of persistent PurchaseOrder
* @param {function} callback - Callback function which is called with any error and the persistent PurchaseOrder
*/
QuickBooks.prototype.getPurchaseOrder = function(id, callback) {
module.read(this, 'purchaseOrder', id, callback)
}
/**
* Retrieves the RefundReceipt from QuickBooks
*
* @param {string} Id - The Id of persistent RefundReceipt
* @param {function} callback - Callback function which is called with any error and the persistent RefundReceipt
*/
QuickBooks.prototype.getRefundReceipt = function(id, callback) {
module.read(this, 'refundReceipt', id, callback)
}
/**
* Retrieves the Reports from QuickBooks
*
* @param {string} Id - The Id of persistent Reports
* @param {function} callback - Callback function which is called with any error and the persistent Reports
*/
QuickBooks.prototype.getReports = function(id, callback) {
module.read(this, 'reports', id, callback)
}
/**
* Retrieves the SalesReceipt from QuickBooks
*
* @param {string} Id - The Id of persistent SalesReceipt
* @param {function} callback - Callback function which is called with any error and the persistent SalesReceipt
*/
QuickBooks.prototype.getSalesReceipt = function(id, callback) {
module.read(this, 'salesReceipt', id, callback)
}
/**
* Retrieves the SalesReceipt PDF from QuickBooks
*
* @param {string} Id - The Id of persistent SalesReceipt
* @param {function} callback - Callback function which is called with any error and the SalesReceipt PDF
*/
QuickBooks.prototype.getSalesReceiptPdf = function(id, callback) {
module.read(this, 'salesReceipt', id + '/pdf', callback)
}
/**
* Emails the SalesReceipt PDF from QuickBooks to the address supplied in SalesReceipt.BillEmail.EmailAddress
* or the specified 'sendTo' address
*
* @param {string} Id - The Id of persistent SalesReceipt
* @param {string} sendTo - optional email address to send the PDF to. If not provided, address supplied in SalesReceipt.BillEmail.EmailAddress will be used
* @param {function} callback - Callback function which is called with any error and the SalesReceipt PDF
*/
QuickBooks.prototype.sendSalesReceiptPdf = function(id, sendTo, callback) {
var path = '/salesreceipt/' + id + '/send'
callback = _.isFunction(sendTo) ? sendTo : callback
if (sendTo && ! _.isFunction(sendTo)) {
path += '?sendTo=' + sendTo
}
module.request(this, 'post', {url: path}, null, module.unwrap(callback, 'SalesReceipt'))
}
/**
* Retrieves the TaxAgency from QuickBooks
*
* @param {string} Id - The Id of persistent TaxAgency
* @param {function} callback - Callback function which is called with any error and the persistent TaxAgency
*/
QuickBooks.prototype.getTaxAgency = function(id, callback) {
module.read(this, 'taxAgency', id, callback)
}
/**
* Retrieves the TaxCode from QuickBooks
*
* @param {string} Id - The Id of persistent TaxCode
* @param {function} callback - Callback function which is called with any error and the persistent TaxCode
*/
QuickBooks.prototype.getTaxCode = function(id, callback) {
module.read(this, 'taxCode', id, callback)
}
/**
* Retrieves the TaxRate from QuickBooks
*
* @param {string} Id - The Id of persistent TaxRate
* @param {function} callback - Callback function which is called with any error and the persistent TaxRate
*/
QuickBooks.prototype.getTaxRate = function(id, callback) {
module.read(this, 'taxRate', id, callback)
}
/**
* Retrieves the Term from QuickBooks
*
* @param {string} Id - The Id of persistent Term
* @param {function} callback - Callback function which is called with any error and the persistent Term
*/
QuickBooks.prototype.getTerm = function(id, callback) {
module.read(this, 'term', id, callback)
}
/**
* Retrieves the TimeActivity from QuickBooks
*
* @param {string} Id - The Id of persistent TimeActivity
* @param {function} callback - Callback function which is called with any error and the persistent TimeActivity
*/
QuickBooks.prototype.getTimeActivity = function(id, callback) {