1 | |
2 | type SageIntacct = { |
3 | token: string |
4 | } |
5 | |
6 | * Update a customer |
7 | * Updates an existing customer by setting field values. Any fields not provided remain unchanged. Customers included in posted transactions will not be updated. Only new transactions and records will refer to the updated customer information. |
8 |
|
9 |
|
10 | Permissions and other requirements |
11 |
|
12 | SubscriptionAccounts Receivable |
13 | User typeBusiness |
14 | PermissionsList, View, Edit Customers |
15 |
|
16 |
|
17 |
|
18 |
|
19 | */ |
20 | export async function main( |
21 | auth: SageIntacct, |
22 | key: string, |
23 | body: { |
24 | key?: string |
25 | id?: string |
26 | name?: string |
27 | href?: string |
28 | status?: 'active' | 'activeNonPosting' | 'inactive' |
29 | customerType?: { key?: string; id?: string; href?: string } |
30 | parent?: { key?: string; id?: string; name?: string; href?: string } |
31 | salesRepresentative?: { |
32 | key?: string |
33 | id?: string |
34 | name?: string |
35 | href?: string |
36 | } |
37 | taxId?: string |
38 | defaultRevenueGLAccount?: { |
39 | key?: string |
40 | id?: string |
41 | name?: string |
42 | href?: string |
43 | } |
44 | shippingMethod?: { key?: string; id?: string; href?: string } |
45 | creditLimit?: number |
46 | isOnHold?: false | true |
47 | contacts?: { |
48 | default?: { |
49 | key?: string |
50 | id?: string |
51 | href?: string |
52 | lastName?: string |
53 | firstName?: string |
54 | middleName?: string |
55 | prefix?: string |
56 | printAs?: string |
57 | email1?: string |
58 | email2?: string |
59 | phone1?: string |
60 | phone2?: string |
61 | mobile?: string |
62 | pager?: string |
63 | fax?: string |
64 | URL1?: string |
65 | URL2?: string |
66 | companyName?: string |
67 | mailingAddress?: { |
68 | addressLine1?: string |
69 | addressLine2?: string |
70 | addressLine3?: string |
71 | city?: string |
72 | state?: string |
73 | postCode?: string |
74 | country?: string |
75 | } |
76 | } & { |
77 | showInContactList?: false | true |
78 | tax?: { |
79 | isTaxable?: false | true |
80 | group?: { key?: string; id?: string; href?: string } |
81 | } |
82 | electronicInvoiceDetails?: { |
83 | legalCategory?: string |
84 | mainActivity?: string |
85 | typeOfCompany?: string |
86 | registeredCapital?: number |
87 | valueAddedTaxRegime?: string |
88 | } |
89 | internationalTaxId?: string |
90 | } |
91 | primary?: { key?: string; id?: string; href?: string } |
92 | billTo?: { key?: string; id?: string; href?: string } |
93 | shipTo?: { key?: string; id?: string; href?: string } |
94 | } |
95 | contactList?: { |
96 | key?: string |
97 | id?: string |
98 | categoryName?: string |
99 | href?: string |
100 | contact?: { key?: string; id?: string; href?: string } |
101 | audit?: { |
102 | createdDateTime?: string |
103 | modifiedDateTime?: string |
104 | createdBy?: string |
105 | modifiedBy?: string |
106 | } |
107 | customer?: { key?: string; id?: string; href?: string } |
108 | }[] |
109 | audit?: { |
110 | createdDateTime?: string |
111 | modifiedDateTime?: string |
112 | createdBy?: string |
113 | modifiedBy?: string |
114 | } |
115 | customerEmailTemplates?: { |
116 | key?: string |
117 | id?: string |
118 | href?: string |
119 | customer?: { key?: string; id?: string; href?: string } |
120 | txnDefinition?: { href?: string; key?: string; id?: string } |
121 | emailTemplate?: { |
122 | key?: string |
123 | id?: string |
124 | name?: string |
125 | templateType?: 'arInvoice' | 'arStatement' | 'contract' | 'orderEntryTxn' | 'purchasingTxn' |
126 | href?: string |
127 | } |
128 | }[] |
129 | discountPercent?: string |
130 | term?: { key?: string; id?: string; href?: string } |
131 | advanceBillBy?: string |
132 | advanceBillByType?: '' | 'days' | 'months' |
133 | totalDue?: string |
134 | lastInvoiceCreatedDate?: string |
135 | lastStatementGeneratedDate?: string |
136 | resaleNumber?: number |
137 | deliveryOptions?: 'print' | 'email' | 'both' |
138 | overridePriceList?: 'customer' | 'billingContact' | 'shippingContact' |
139 | customerMessage?: { |
140 | key?: string |
141 | id?: string |
142 | message?: string |
143 | href?: string |
144 | } |
145 | currency?: string |
146 | emailOptIn?: false | true |
147 | activationDate?: string |
148 | subscriptionEndDate?: string |
149 | territory?: { key?: string; id?: string; name?: string; href?: string } |
150 | enableOnlineACHPayment?: false | true |
151 | enableOnlineCardPayment?: false | true |
152 | isOneTimeUse?: false | true |
153 | accountGroup?: { key?: string; id?: string; href?: string } |
154 | accountLabel?: { key?: string; id?: string; href?: string } |
155 | attachment?: { key?: string; id?: string; href?: string } |
156 | retainagePercentage?: number |
157 | notes?: string |
158 | priceList?: { key?: string; id?: string; href?: string } |
159 | priceSchedule?: { key?: string; id?: string; href?: string } |
160 | overrideOffsetGLAccount?: { |
161 | key?: string |
162 | id?: string |
163 | name?: string |
164 | href?: string |
165 | } |
166 | customerRestriction?: 'unrestricted' | 'rootOnly' | 'restricted' |
167 | restrictedLocations?: { |
168 | key?: string |
169 | id?: string |
170 | href?: string |
171 | location?: { key?: string; id?: string; href?: string } |
172 | locationGroup?: { key?: string; id?: string; href?: string } |
173 | customer?: { key?: string; id?: string; href?: string } |
174 | }[] |
175 | restrictedDepartments?: { |
176 | key?: string |
177 | id?: string |
178 | href?: string |
179 | department?: { key?: string; id?: string; href?: string } |
180 | departmentGroup?: { key?: string; id?: string; href?: string } |
181 | customer?: { key?: string; id?: string; href?: string } |
182 | }[] |
183 | entity?: { key?: string; id?: string; name?: string; href?: string } |
184 | } & { id?: {} } |
185 | ) { |
186 | const url = new URL( |
187 | `https://api.intacct.com/ia/api/v1/objects/accounts-receivable/customer/${key}` |
188 | ) |
189 |
|
190 | const response = await fetch(url, { |
191 | method: 'PATCH', |
192 | headers: { |
193 | 'Content-Type': 'application/json', |
194 | Authorization: 'Bearer ' + auth.token |
195 | }, |
196 | body: JSON.stringify(body) |
197 | }) |
198 | if (!response.ok) { |
199 | const text = await response.text() |
200 | throw new Error(`${response.status} ${text}`) |
201 | } |
202 | return await response.json() |
203 | } |
204 |
|