-
Notifications
You must be signed in to change notification settings - Fork 37
/
AvaTaxClient.js
13952 lines (13588 loc) · 670 KB
/
AvaTaxClient.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
/*
* AvaTax Software Development Kit for JavaScript
*
* (c) 2004-2018 Avalara, Inc.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Justin Soliz <justin.soliz@avalara.com>
* @author Ted Spence <ted.spence@avalara.com>
* @copyright 2004-2018 Avalara, Inc.
* @license https://www.apache.org/licenses/LICENSE-2.0
* @version 22.2.0
* @link https://github.com/avadev/AvaTax-REST-V2-JS-SDK
*/
import fetch from 'isomorphic-fetch';
import { createBasicAuthHeader } from './utils/basic_auth';
import { withTimeout } from './utils/withTimeout';
export default class AvaTaxClient {
/**
* Construct a new AvaTaxClient
*
* @constructor
* @param string appName Specify the name of your application here. Should not contain any semicolons.
* @param string appVersion Specify the version number of your application here. Should not contain any semicolons.
* @param string machineName Specify the machine name of the machine on which this code is executing here. Should not contain any semicolons.
* @param string environment Indicates which server to use; acceptable values are "sandbox" or "production", or the full URL of your AvaTax instance.
* @param number timeout Specify the timeout for AvaTax requests; default value 20 minutes.
*/
constructor({ appName, appVersion, machineName, environment, timeout = 1200000 }) {
this.appNM=appName;
this.appVer=appVersion;
this.machineNM=machineName
this.baseUrl = 'https://rest.avatax.com';
if (environment == 'sandbox') {
this.baseUrl = 'https://sandbox-rest.avatax.com';
} else if (
typeof environment !== "undefined" &&
(environment.substring(0, 8) == 'https://' ||
environment.substring(0, 7) == 'http://')
) {
this.baseUrl = environment;
}
this.timeout = timeout;
}
/**
* Configure this client to use the specified username/password security settings
*
* @param string username The username for your AvaTax user account
* @param string password The password for your AvaTax user account
* @param int accountId The account ID of your avatax account
* @param string licenseKey The license key of your avatax account
* @param string bearerToken The OAuth 2.0 token provided by Avalara Identity
* @return AvaTaxClient
*/
withSecurity({ username, password, accountId, licenseKey, bearerToken }) {
if (username != null && password != null) {
this.auth = createBasicAuthHeader(username, password);
} else if (accountId != null && licenseKey != null) {
this.auth = createBasicAuthHeader(accountId, licenseKey);
} else if (bearerToken != null) {
this.auth = 'Bearer ' + bearerToken;
}
return this;
}
/**
* Make a single REST call to the AvaTax v2 API server
*
* @param string url The relative path of the API on the server
* @param string verb The HTTP verb being used in this request
* @param string payload The request body, if this is being sent to a POST/PUT API call
*/
restCall({ url, verb, payload, clientId="" }) {
return withTimeout(this.timeout, fetch(url, {
method: verb,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: this.auth,
'X-Avalara-Client': clientId
},
body: JSON.stringify(payload)
})).then(res => {
var contentType = res.headers._headers['content-type'];
var contentLength = res.headers._headers['content-length'];
if (typeof contentLength !== "undefined" && contentLength != null)
{
contentLength = res.headers._headers['content-length'][0];
}
if (contentType[0] === 'application/vnd.ms-excel' || contentType[0] === 'text/csv') {
return res;
}
if (res.headers._headers['content-type'].includes('application/json'))
{
if (typeof contentLength !== "undefined" && contentLength != null && contentLength == 0 && parseInt(res.status/100)==2 ){
return null;
}
}
return res.json();
}).then(json => {
// handle error
if (json && json.length>0 && json.error) {
let ex = new Error(json.error.message);
ex.code = json.error.code;
ex.target = json.error.target;
ex.details = json.error.details;
throw ex;
} else {
return json;
}
})
}
/**
* Construct a URL with query string parameters
*
* @param string url The root URL of the API being called
* @param string parameters A list of name-value pairs in a javascript object to create as query string parameters
*/
buildUrl({ url, parameters }) {
var qs = '';
for (var key in parameters) {
var value = parameters[key];
if (value) {
qs += encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&';
}
}
if (qs.length > 0) {
qs = qs.substring(0, qs.length - 1); //chop off last "&"
url = url + '?' + qs;
}
return this.baseUrl + url;
}
/**
* Reset this account's license key
* Resets the existing license key for this account to a new key.
*
* To reset your account, you must specify the ID of the account you wish to reset and confirm the action.
*
* This API is only available to account administrators for the account in question, and may only be called after
* an account has been activated by reading and accepting Avalara's terms and conditions. To activate your account
* please log onto the AvaTax website or call the `ActivateAccount` API.
*
* You can only reset license with 'Default' license key name.
* Resetting a license key cannot be undone. Any previous license keys will immediately cease to work when a new key is created.
*
* When you call this API, all account administrators for this account will receive an email with the newly updated license key.
* The email will specify which user reset the license key and it will contain the new key to use to update your connectors.
* Note: The reset license key functionality will only be available for existing active license key i.e. when you reset license key for the account, the Default license key will be reset.The reset license key functionality is not available for newly created license keys i.e. license keys other than Default
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, Registrar, SiteAdmin, SSTAdmin, SystemAdmin, TechnicalSupportAdmin.
* Swagger Name: AvaTaxClient
*
*
* @param int id The ID of the account you wish to update.
* @param object model A request confirming that you wish to reset the license key of this account.
* @return object
*/
accountResetLicenseKey({ id, model } = {}) {
var path = this.buildUrl({
url: `/api/v2/accounts/${id}/resetlicensekey`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'post', payload: model, clientId: strClientId });
}
/**
* Activate an account by accepting terms and conditions
* Activate the account specified by the unique accountId number.
*
* This activation request can only be called by account administrators. You must indicate
* that you have read and accepted Avalara's terms and conditions to call this API.
*
* Once you have activated your account, use the `AccountResetLicenseKey` API to generate
* a license key for your account.
*
* If you have not read or accepted the terms and conditions, this API call will return the
* unchanged account model.
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, FirmAdmin, Registrar, SiteAdmin, SSTAdmin, SystemAdmin, TechnicalSupportAdmin.
* Swagger Name: AvaTaxClient
*
*
* @param int id The ID of the account to activate
* @param object model The activation request
* @return object
*/
activateAccount({ id, model } = {}) {
var path = this.buildUrl({
url: `/api/v2/accounts/${id}/activate`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'post', payload: model, clientId: strClientId });
}
/**
* Retrieve audit history for an account.
* Retrieve audit trace history for an account.
*
* Your audit trace history contains a record of all API calls made against the AvaTax REST API that returned an error. You can use this API to investigate
* problems and see exactly what information was sent back and forth between your code and AvaTax.
*
* When specifying a start and end datetime, please include a valid timezone indicator, such as the "Z" present in the examples for the start and end query parameters.
* You can learn more about valid time zone designators at https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators.
*
* This API enforces limits to the amount of data retrieved. These limits are subject to change.
*
* * You may request data from a maximum of a one-hour time period.
* * The amount of data and number of API calls returned by this API are limited and may be adjusted at any time.
* * Old records may be migrated out of immediately available storage. To request older data, please contact your account manager.
* * New records must migrate to available storage before they can be retrieved. You may need to wait a period of time before newly created records can be fetched.
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountUser, CompanyAdmin, CompanyUser, Compliance Root User, ComplianceAdmin, ComplianceUser, CSPAdmin, CSPTester, FirmAdmin, FirmUser, Registrar, SiteAdmin, SSTAdmin, SystemAdmin, TechnicalSupportAdmin, TechnicalSupportUser, TreasuryAdmin, TreasuryUser.
* Swagger Name: AvaTaxClient
*
*
* @param int id The ID of the account you wish to audit.
* @param string start The start datetime of audit history you with to retrieve, e.g. "2018-06-08T17:00:00Z". Defaults to the past 15 minutes.
* @param string end The end datetime of audit history you with to retrieve, e.g. "2018-06-08T17:15:00Z. Defaults to the current time. Maximum of an hour after the start time.
* @param int top If nonzero, return no more than this number of results. Used with `$skip` to provide pagination for large datasets. Unless otherwise specified, the maximum number of records that can be returned from an API call is 1,000 records.
* @param int skip If nonzero, skip this number of results before returning data. Used with `$top` to provide pagination for large datasets.
* @return FetchResult
*/
auditAccount({ id, start, end, top, skip } = {}) {
var path = this.buildUrl({
url: `/api/v2/accounts/${id}/audit`,
parameters: {
start: start,
end: end,
$top: top,
$skip: skip
}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'get', payload: null, clientId: strClientId });
}
/**
* Create license key for this account
* Creates a new license key for this account.
*
* To create a license key for your account, you must specify the ID of the account and license key name.
*
* This API is only available to account administrators for the account in question, and may only be called after
* an account has been activated by reading and accepting Avalara's terms and conditions. To activate your account
* please log onto the AvaTax website or call the `ActivateAccount` API.
*
* You will reference this key using license key name. The existing license key will be using 'Default' as license key name.
* Hence make sure that the license key name is unique per account considering the existing license key name 'Default'
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, Registrar, SiteAdmin, SSTAdmin, SystemAdmin, TechnicalSupportAdmin.
* Swagger Name: AvaTaxClient
*
*
* @param int id The ID of the account you wish to update.
* @param object model
* @return object
*/
createLicenseKey({ id, model } = {}) {
var path = this.buildUrl({
url: `/api/v2/accounts/${id}/licensekey`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'post', payload: model, clientId: strClientId });
}
/**
* Delete license key for this account by license key name
* Deletes the license key for this account using license key name.
*
* To delete a license key for your account, you must specify the accountID of the account and license key name.
*
* This API is only available to account administrators for the account in question.
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, Registrar, SiteAdmin, SSTAdmin, SystemAdmin, TechnicalSupportAdmin.
* Swagger Name: AvaTaxClient
*
*
* @param int id The ID of the account you wish to update.
* @param string licensekeyname The license key name you wish to update.
* @return object[]
*/
deleteLicenseKey({ id, licensekeyname } = {}) {
var path = this.buildUrl({
url: `/api/v2/accounts/${id}/licensekey/${licensekeyname}`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'delete', payload: null, clientId: strClientId });
}
/**
* Retrieve a single account
* Get the account object identified by this URL.
* You may use the '$include' parameter to fetch additional nested data:
*
* * Subscriptions
* * Users
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountUser, CompanyAdmin, CompanyUser, Compliance Root User, ComplianceAdmin, ComplianceUser, CSPAdmin, CSPTester, FirmAdmin, FirmUser, Registrar, SiteAdmin, SSTAdmin, SystemAdmin, TechnicalSupportAdmin, TechnicalSupportUser, TreasuryAdmin, TreasuryUser.
* Swagger Name: AvaTaxClient
*
*
* @param int id The ID of the account to retrieve
* @param string include A comma separated list of special fetch options
* @return object
*/
getAccount({ id, include } = {}) {
var path = this.buildUrl({
url: `/api/v2/accounts/${id}`,
parameters: {
$include: include
}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'get', payload: null, clientId: strClientId });
}
/**
* Get configuration settings for this account
* Retrieve a list of all configuration settings tied to this account.
*
* Configuration settings provide you with the ability to control features of your account and of your
* tax software. The category names `TaxServiceConfig` and `AddressServiceConfig` are reserved for
* Avalara internal software configuration values; to store your own account-level settings, please
* create a new category name that begins with `X-`, for example, `X-MyCustomCategory`.
*
* Account settings are permanent settings that cannot be deleted. You can set the value of an
* account setting to null if desired.
*
* Avalara-based account settings for `TaxServiceConfig` and `AddressServiceConfig` affect your account's
* tax calculation and address resolution, and should only be changed with care.
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountUser, CompanyAdmin, CompanyUser, CSPAdmin, CSPTester, SiteAdmin, SSTAdmin, SystemAdmin, TechnicalSupportAdmin, TechnicalSupportUser.
* Swagger Name: AvaTaxClient
*
*
* @param int id
* @return object[]
*/
getAccountConfiguration({ id } = {}) {
var path = this.buildUrl({
url: `/api/v2/accounts/${id}/configuration`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'get', payload: null, clientId: strClientId });
}
/**
* Retrieve license key by license key name
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountUser, CompanyAdmin, CompanyUser, Compliance Root User, ComplianceAdmin, ComplianceUser, CSPAdmin, CSPTester, FirmAdmin, FirmUser, Registrar, SiteAdmin, SSTAdmin, SystemAdmin, TechnicalSupportAdmin, TechnicalSupportUser, TreasuryAdmin, TreasuryUser.
* Swagger Name: AvaTaxClient
*
*
* @param int id The ID of the account to retrieve
* @param string licensekeyname The ID of the account to retrieve
* @return object
*/
getLicenseKey({ id, licensekeyname } = {}) {
var path = this.buildUrl({
url: `/api/v2/accounts/${id}/licensekey/${licensekeyname}`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'get', payload: null, clientId: strClientId });
}
/**
* Retrieve all license keys for this account
* Gets list of all the license keys used by the account.
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountUser, CompanyAdmin, CompanyUser, Compliance Root User, ComplianceAdmin, ComplianceUser, CSPAdmin, CSPTester, FirmAdmin, FirmUser, Registrar, SiteAdmin, SSTAdmin, SystemAdmin, TechnicalSupportAdmin, TechnicalSupportUser, TreasuryAdmin, TreasuryUser.
* Swagger Name: AvaTaxClient
*
*
* @param int id The ID of the account to retrieve
* @return object[]
*/
getLicenseKeys({ id } = {}) {
var path = this.buildUrl({
url: `/api/v2/accounts/${id}/licensekeys`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'get', payload: null, clientId: strClientId });
}
/**
* Retrieve all accounts
* List all account objects that can be seen by the current user.
*
* This API lists all accounts you are allowed to see. In general, most users will only be able to see their own account.
*
* Search for specific objects using the criteria in the `$filter` parameter; full documentation is available on [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/) .
* Paginate your results using the `$top`, `$skip`, and `$orderby` parameters.
* You may specify one or more of the following values in the `$include` parameter to fetch additional nested data, using commas to separate multiple values:
*
* * Subscriptions
* * Users
*
* For more information about filtering in REST, please see the documentation at http://developer.avalara.com/avatax/filtering-in-rest/ .
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountUser, CompanyAdmin, CompanyUser, Compliance Root User, ComplianceAdmin, ComplianceUser, CSPAdmin, CSPTester, FirmAdmin, FirmUser, Registrar, SiteAdmin, SSTAdmin, SystemAdmin, TechnicalSupportAdmin, TechnicalSupportUser, TreasuryAdmin, TreasuryUser.
* Swagger Name: AvaTaxClient
*
*
* @param string include A comma separated list of objects to fetch underneath this account. Any object with a URL path underneath this account can be fetched by specifying its name.
* @param string filter A filter statement to identify specific records to retrieve. For more information on filtering, see [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/).<br />*Not filterable:* subscriptions, users
* @param int top If nonzero, return no more than this number of results. Used with `$skip` to provide pagination for large datasets. Unless otherwise specified, the maximum number of records that can be returned from an API call is 1,000 records.
* @param int skip If nonzero, skip this number of results before returning data. Used with `$top` to provide pagination for large datasets.
* @param string orderBy A comma separated list of sort statements in the format `(fieldname) [ASC|DESC]`, for example `id ASC`.
* @return FetchResult
*/
queryAccounts({ include, filter, top, skip, orderBy } = {}) {
var path = this.buildUrl({
url: `/api/v2/accounts`,
parameters: {
$include: include,
$filter: filter,
$top: top,
$skip: skip,
$orderBy: orderBy
}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'get', payload: null, clientId: strClientId });
}
/**
* Change configuration settings for this account
* Update configuration settings tied to this account.
*
* Configuration settings provide you with the ability to control features of your account and of your
* tax software. The category names `TaxServiceConfig` and `AddressServiceConfig` are reserved for
* Avalara internal software configuration values; to store your own account-level settings, please
* create a new category name that begins with `X-`, for example, `X-MyCustomCategory`.
*
* Account settings are permanent settings that cannot be deleted. You can set the value of an
* account setting to null if desired.
*
* Avalara-based account settings for `TaxServiceConfig` and `AddressServiceConfig` affect your account's
* tax calculation and address resolution, and should only be changed with care.
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, CSPTester, SSTAdmin, TechnicalSupportAdmin.
* Swagger Name: AvaTaxClient
*
*
* @param int id
* @param object[] model
* @return object[]
*/
setAccountConfiguration({ id, model } = {}) {
var path = this.buildUrl({
url: `/api/v2/accounts/${id}/configuration`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'post', payload: model, clientId: strClientId });
}
/**
* Retrieve geolocation information for a specified address
* Resolve an address against Avalara's address-validation system. If the address can be resolved, this API
* provides the latitude and longitude of the resolved location. The value 'resolutionQuality' can be used
* to identify how closely this address can be located. If the address cannot be clearly located, use the
* 'messages' structure to learn more about problems with this address.
* This is the same API as the POST /api/v2/addresses/resolve endpoint.
* Both verbs are supported to provide for flexible implementation.
*
* In order to get any evaluation for an address, please provide at least one of the following fields/pairs:
* 1. postal code
* 2. line1 + city + region
* 3. line1 + postal code
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountOperator, AccountUser, CompanyAdmin, CompanyUser, CSPTester, SSTAdmin, TechnicalSupportAdmin, TechnicalSupportUser.
* * This API depends on the following active services:*Required* (all): AutoAddress.
* Swagger Name: AvaTaxClient
*
*
* @param string line1 Line 1
* @param string line2 Line 2
* @param string line3 Line 3
* @param string city City
* @param string region State / Province / Region
* @param string postalCode Postal Code / Zip Code
* @param string country Two character ISO 3166 Country Code (see /api/v2/definitions/countries for a full list)
* @param string textCase selectable text case for address validation (See TextCase::* for a list of allowable values)
* @return object
*/
resolveAddress({ line1, line2, line3, city, region, postalCode, country, textCase } = {}) {
var path = this.buildUrl({
url: `/api/v2/addresses/resolve`,
parameters: {
line1: line1,
line2: line2,
line3: line3,
city: city,
region: region,
postalCode: postalCode,
country: country,
textCase: textCase
}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'get', payload: null, clientId: strClientId });
}
/**
* Retrieve geolocation information for a specified address
* Resolve an address against Avalara's address-validation system. If the address can be resolved, this API
* provides the latitude and longitude of the resolved location. The value 'resolutionQuality' can be used
* to identify how closely this address can be located. If the address cannot be clearly located, use the
* 'messages' structure to learn more about problems with this address.
* This is the same API as the GET /api/v2/addresses/resolve endpoint.
* Both verbs are supported to provide for flexible implementation.
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountOperator, AccountUser, CompanyAdmin, CompanyUser, CSPTester, SSTAdmin, TechnicalSupportAdmin, TechnicalSupportUser.
* * This API depends on the following active services:*Required* (all): AutoAddress.
* Swagger Name: AvaTaxClient
*
*
* @param object model The address to resolve
* @return object
*/
resolveAddressPost({ model } = {}) {
var path = this.buildUrl({
url: `/api/v2/addresses/resolve`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'post', payload: model, clientId: strClientId });
}
/**
* Create a lookup file for a company
*
* Swagger Name: AvaTaxClient
*
*
* @param int accountId The ID of the account for the company
* @param int companyId The ID of the company for which the lookup file is to be created
* @param object model The lookup file you wish to create
* @return object
*/
createCompanyLookupFile({ accountId, companyId, model } = {}) {
var path = this.buildUrl({
url: `/api/v2/advancedrules/accounts/${accountId}/companies/${companyId}/lookupFiles`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'post', payload: model, clientId: strClientId });
}
/**
* Delete a lookup file
*
* Swagger Name: AvaTaxClient
*
*
* @param int accountId The ID of the account for the company the lookup file is for
* @param string id The unique ID/GUID for the company lookup file to be deleted
* @return object[]
*/
deleteLookupFile({ accountId, id } = {}) {
var path = this.buildUrl({
url: `/api/v2/advancedrules/accounts/${accountId}/lookupFiles/${id}`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'delete', payload: null, clientId: strClientId });
}
/**
* Get the lookup files for a company
*
* Swagger Name: AvaTaxClient
*
*
* @param int accountId The account ID for the company
* @param int companyId The ID of the company for which to retrieve lookup files
* @return FetchResult
*/
getCompanyLookupFiles({ accountId, companyId } = {}) {
var path = this.buildUrl({
url: `/api/v2/advancedrules/accounts/${accountId}/companies/${companyId}/lookupFiles`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'get', payload: null, clientId: strClientId });
}
/**
* Get a lookup file for an accountId and companyLookupFileId
*
* Swagger Name: AvaTaxClient
*
*
* @param int accountId The ID of the account for the lookup file
* @param string id The unique ID/GUID of the company lookup file to return
* @return object
*/
getLookupFile({ accountId, id } = {}) {
var path = this.buildUrl({
url: `/api/v2/advancedrules/accounts/${accountId}/lookupFiles/${id}`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'get', payload: null, clientId: strClientId });
}
/**
* Update a lookup file
*
* Swagger Name: AvaTaxClient
*
*
* @param int accountId The ID of the account for the company the lookup file is for
* @param string id The unique ID/GUID of the company lookup file to be updated
* @param object model The new values to update the lookup file
* @return object
*/
updateLookupFile({ accountId, id, model } = {}) {
var path = this.buildUrl({
url: `/api/v2/advancedrules/accounts/${accountId}/lookupFiles/${id}`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'put', payload: model, clientId: strClientId });
}
/**
* Create a new AvaFileForm
* Create one or more AvaFileForms
* A 'AvaFileForm' represents a form supported by our returns team
*
* ### Security Policies
*
* * This API requires the user role Compliance Root User.
* * This API depends on the following active services:*Returns* (at least one of): Mrs, MRSComplianceManager, AvaTaxCsp.*Firm Managed* (for accounts managed by a firm): ARA, ARAManaged.
* Swagger Name: AvaTaxClient
*
*
* @param object[] model The AvaFileForm you wish to create.
* @return object[]
*/
createAvaFileForms({ model } = {}) {
var path = this.buildUrl({
url: `/api/v2/avafileforms`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'post', payload: model, clientId: strClientId });
}
/**
* Delete a single AvaFileForm
* Marks the existing AvaFileForm object at this URL as deleted.
*
* ### Security Policies
*
* * This API requires one of the following user roles: Compliance Root User, ComplianceUser, FirmAdmin.
* * This API depends on the following active services:*Returns* (at least one of): Mrs, MRSComplianceManager, AvaTaxCsp.*Firm Managed* (for accounts managed by a firm): ARA, ARAManaged.
* Swagger Name: AvaTaxClient
*
*
* @param int id The ID of the AvaFileForm you wish to delete.
* @return object[]
*/
deleteAvaFileForm({ id } = {}) {
var path = this.buildUrl({
url: `/api/v2/avafileforms/${id}`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'delete', payload: null, clientId: strClientId });
}
/**
* Retrieve a single AvaFileForm
* Get the AvaFileForm object identified by this URL.
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountOperator, CompanyAdmin, CompanyUser, Compliance Root User, Compliance Temp User, ComplianceAdmin, ComplianceUser, FirmAdmin, FirmUser, SystemAdmin, TechnicalSupportAdmin, TechnicalSupportUser, TreasuryAdmin.
* * This API depends on the following active services:*Returns* (at least one of): Mrs, MRSComplianceManager, AvaTaxCsp.*Firm Managed* (for accounts managed by a firm): ARA, ARAManaged.
* Swagger Name: AvaTaxClient
*
*
* @param int id The primary key of this AvaFileForm
* @return object
*/
getAvaFileForm({ id } = {}) {
var path = this.buildUrl({
url: `/api/v2/avafileforms/${id}`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'get', payload: null, clientId: strClientId });
}
/**
* Retrieve all AvaFileForms
* Search for specific objects using the criteria in the `$filter` parameter; full documentation is available on [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/) .
* Paginate your results using the `$top`, `$skip`, and `$orderby` parameters.
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountOperator, CompanyAdmin, CompanyUser, Compliance Root User, Compliance Temp User, ComplianceAdmin, ComplianceUser, FirmAdmin, FirmUser, SystemAdmin, TechnicalSupportAdmin, TechnicalSupportUser, TreasuryAdmin.
* * This API depends on the following active services:*Returns* (at least one of): Mrs, MRSComplianceManager, AvaTaxCsp.*Firm Managed* (for accounts managed by a firm): ARA, ARAManaged.
* Swagger Name: AvaTaxClient
*
*
* @param string filter A filter statement to identify specific records to retrieve. For more information on filtering, see [Filtering in REST](http://developer.avalara.com/avatax/filtering-in-rest/).<br />*Not filterable:* outletTypeId
* @param int top If nonzero, return no more than this number of results. Used with `$skip` to provide pagination for large datasets. Unless otherwise specified, the maximum number of records that can be returned from an API call is 1,000 records.
* @param int skip If nonzero, skip this number of results before returning data. Used with `$top` to provide pagination for large datasets.
* @param string orderBy A comma separated list of sort statements in the format `(fieldname) [ASC|DESC]`, for example `id ASC`.
* @return FetchResult
*/
queryAvaFileForms({ filter, top, skip, orderBy } = {}) {
var path = this.buildUrl({
url: `/api/v2/avafileforms`,
parameters: {
$filter: filter,
$top: top,
$skip: skip,
$orderBy: orderBy
}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'get', payload: null, clientId: strClientId });
}
/**
* Update a AvaFileForm
* All data from the existing object will be replaced with data in the object you PUT.
* To set a field's value to null, you may either set its value to null or omit that field from the object you post.
*
* ### Security Policies
*
* * This API requires the user role Compliance Root User.
* * This API depends on the following active services:*Returns* (at least one of): Mrs, MRSComplianceManager, AvaTaxCsp.*Firm Managed* (for accounts managed by a firm): ARA, ARAManaged.
* Swagger Name: AvaTaxClient
*
*
* @param int id The ID of the AvaFileForm you wish to update
* @param object model The AvaFileForm model you wish to update.
* @return object
*/
updateAvaFileForm({ id, model } = {}) {
var path = this.buildUrl({
url: `/api/v2/avafileforms/${id}`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'put', payload: model, clientId: strClientId });
}
/**
* Cancel an in progress batch
* Marks the in progress batch identified by this URL as cancelled.
*
* Only JSON batches can be cancelled. If you attempt to cancel a file batch, you will receive an error message.
*
* Only in progress batches can be cancelled. If you attempt to cancel a batch that its status is not Waiting or Processing, you will receive an error message.
* Cancelling an in progress batch does not delete any transactions that were created before the cancellation.
*
* Because the batch system processes with a degree of concurrency, and
* because of batch sizes in the queue vary, AvaTax API is unable to accurately
* predict when a batch will complete. If high performance processing is
* required, please use the
* [CreateTransaction API](https://developer.avalara.com/api-reference/avatax/rest/v2/methods/Transactions/CreateTransaction/).
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountOperator, CompanyAdmin, CSPTester, SSTAdmin, SystemAdmin, SystemOperator, TechnicalSupportAdmin.
* Swagger Name: AvaTaxClient
*
*
* @param int companyId The ID of the company that owns this batch.
* @param int id The ID of the batch to cancel.
* @return object
*/
cancelBatch({ companyId, id } = {}) {
var path = this.buildUrl({
url: `/api/v2/companies/${companyId}/batches/${id}/cancel`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'post', payload: null, clientId: strClientId });
}
/**
* Create a new batch
* Create one or more new batch objects attached to this company.
*
* Each batch object may have one or more file objects (currently only one file is supported).
*
* When a batch is created, it is added to the AvaTax Batch Queue and will be
* processed as quickly as possible in the order it was received. To check the
* status of a batch, fetch the batch and retrieve the results of the batch
* operation.
*
* Because the batch system processes with a degree of concurrency, and
* because of batch sizes in the queue vary, AvaTax API is unable to accurately
* predict when a batch will complete. If high performance processing is
* required, please use the
* [CreateTransaction API](https://developer.avalara.com/api-reference/avatax/rest/v2/methods/Transactions/CreateTransaction/).
*
* The maximum content length of the request body is limited to 28.6 MB. If this limit
* is exceeded, a 404 Not Found status will be returned (possibly with a CORS error if
* the API is called from a browser). In this situation, please split the request into
* smaller batches.
*
* ### Security Policies
*
* * This API requires one of the following user roles: AccountAdmin, AccountOperator, CompanyAdmin, CSPTester, SSTAdmin, SystemAdmin, SystemOperator, TechnicalSupportAdmin.
* Swagger Name: AvaTaxClient
*
*
* @param int companyId The ID of the company that owns this batch.
* @param object[] model The batch you wish to create.
* @return object[]
*/
createBatches({ companyId, model } = {}) {
var path = this.buildUrl({
url: `/api/v2/companies/${companyId}/batches`,
parameters: {}
});
var strClientId =
this.appNM +
'; ' +
this.appVer +
'; JavascriptSdk; 22.2.0; ' +
this.machineNM;
return this.restCall({ url: path, verb: 'post', payload: model, clientId: strClientId });
}
/**
* Create a new transaction batch
* Create a new transaction batch objects attached to this company.
*
* When a transaction batch is created, it is added to the AvaTax Batch v2 Queue and will be