1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Updates a specific draft expense claim receipts |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | ReceiptID: string, |
12 | unitdp: string | undefined, |
13 | xero_tenant_id: string, |
14 | Idempotency_Key: string, |
15 | body: { |
16 | Receipts?: { |
17 | Date?: string |
18 | Contact?: { |
19 | ContactID?: string |
20 | MergedToContactID?: string |
21 | ContactNumber?: string |
22 | AccountNumber?: string |
23 | ContactStatus?: 'ACTIVE' | 'ARCHIVED' | 'GDPRREQUEST' |
24 | Name?: string |
25 | FirstName?: string |
26 | LastName?: string |
27 | CompanyNumber?: string |
28 | EmailAddress?: string |
29 | ContactPersons?: { |
30 | FirstName?: string |
31 | LastName?: string |
32 | EmailAddress?: string |
33 | IncludeInEmails?: false | true |
34 | }[] |
35 | BankAccountDetails?: string |
36 | TaxNumber?: string |
37 | AccountsReceivableTaxType?: string |
38 | AccountsPayableTaxType?: string |
39 | Addresses?: { |
40 | AddressType?: 'POBOX' | 'STREET' |
41 | AddressLine1?: string |
42 | AddressLine2?: string |
43 | AddressLine3?: string |
44 | AddressLine4?: string |
45 | City?: string |
46 | Region?: string |
47 | PostalCode?: string |
48 | Country?: string |
49 | AttentionTo?: string |
50 | }[] |
51 | Phones?: { |
52 | PhoneType?: 'DEFAULT' | 'DDI' | 'MOBILE' | 'FAX' | 'OFFICE' |
53 | PhoneNumber?: string |
54 | PhoneAreaCode?: string |
55 | PhoneCountryCode?: string |
56 | }[] |
57 | IsSupplier?: false | true |
58 | IsCustomer?: false | true |
59 | SalesDefaultLineAmountType?: 'INCLUSIVE' | 'EXCLUSIVE' | 'NONE' |
60 | PurchasesDefaultLineAmountType?: 'INCLUSIVE' | 'EXCLUSIVE' | 'NONE' |
61 | DefaultCurrency?: |
62 | | 'AED' |
63 | | 'AFN' |
64 | | 'ALL' |
65 | | 'AMD' |
66 | | 'ANG' |
67 | | 'AOA' |
68 | | 'ARS' |
69 | | 'AUD' |
70 | | 'AWG' |
71 | | 'AZN' |
72 | | 'BAM' |
73 | | 'BBD' |
74 | | 'BDT' |
75 | | 'BGN' |
76 | | 'BHD' |
77 | | 'BIF' |
78 | | 'BMD' |
79 | | 'BND' |
80 | | 'BOB' |
81 | | 'BRL' |
82 | | 'BSD' |
83 | | 'BTN' |
84 | | 'BWP' |
85 | | 'BYN' |
86 | | 'BYR' |
87 | | 'BZD' |
88 | | 'CAD' |
89 | | 'CDF' |
90 | | 'CHF' |
91 | | 'CLF' |
92 | | 'CLP' |
93 | | 'CNY' |
94 | | 'COP' |
95 | | 'CRC' |
96 | | 'CUC' |
97 | | 'CUP' |
98 | | 'CVE' |
99 | | 'CZK' |
100 | | 'DJF' |
101 | | 'DKK' |
102 | | 'DOP' |
103 | | 'DZD' |
104 | | 'EEK' |
105 | | 'EGP' |
106 | | 'ERN' |
107 | | 'ETB' |
108 | | 'EUR' |
109 | | 'FJD' |
110 | | 'FKP' |
111 | | 'GBP' |
112 | | 'GEL' |
113 | | 'GHS' |
114 | | 'GIP' |
115 | | 'GMD' |
116 | | 'GNF' |
117 | | 'GTQ' |
118 | | 'GYD' |
119 | | 'HKD' |
120 | | 'HNL' |
121 | | 'HRK' |
122 | | 'HTG' |
123 | | 'HUF' |
124 | | 'IDR' |
125 | | 'ILS' |
126 | | 'INR' |
127 | | 'IQD' |
128 | | 'IRR' |
129 | | 'ISK' |
130 | | 'JMD' |
131 | | 'JOD' |
132 | | 'JPY' |
133 | | 'KES' |
134 | | 'KGS' |
135 | | 'KHR' |
136 | | 'KMF' |
137 | | 'KPW' |
138 | | 'KRW' |
139 | | 'KWD' |
140 | | 'KYD' |
141 | | 'KZT' |
142 | | 'LAK' |
143 | | 'LBP' |
144 | | 'LKR' |
145 | | 'LRD' |
146 | | 'LSL' |
147 | | 'LTL' |
148 | | 'LVL' |
149 | | 'LYD' |
150 | | 'MAD' |
151 | | 'MDL' |
152 | | 'MGA' |
153 | | 'MKD' |
154 | | 'MMK' |
155 | | 'MNT' |
156 | | 'MOP' |
157 | | 'MRO' |
158 | | 'MRU' |
159 | | 'MUR' |
160 | | 'MVR' |
161 | | 'MWK' |
162 | | 'MXN' |
163 | | 'MXV' |
164 | | 'MYR' |
165 | | 'MZN' |
166 | | 'NAD' |
167 | | 'NGN' |
168 | | 'NIO' |
169 | | 'NOK' |
170 | | 'NPR' |
171 | | 'NZD' |
172 | | 'OMR' |
173 | | 'PAB' |
174 | | 'PEN' |
175 | | 'PGK' |
176 | | 'PHP' |
177 | | 'PKR' |
178 | | 'PLN' |
179 | | 'PYG' |
180 | | 'QAR' |
181 | | 'RON' |
182 | | 'RSD' |
183 | | 'RUB' |
184 | | 'RWF' |
185 | | 'SAR' |
186 | | 'SBD' |
187 | | 'SCR' |
188 | | 'SDG' |
189 | | 'SEK' |
190 | | 'SGD' |
191 | | 'SHP' |
192 | | 'SKK' |
193 | | 'SLE' |
194 | | 'SLL' |
195 | | 'SOS' |
196 | | 'SRD' |
197 | | 'STD' |
198 | | 'STN' |
199 | | 'SVC' |
200 | | 'SYP' |
201 | | 'SZL' |
202 | | 'THB' |
203 | | 'TJS' |
204 | | 'TMT' |
205 | | 'TND' |
206 | | 'TOP' |
207 | | 'TRY' |
208 | | 'TTD' |
209 | | 'TWD' |
210 | | 'TZS' |
211 | | 'UAH' |
212 | | 'UGX' |
213 | | 'USD' |
214 | | 'UYU' |
215 | | 'UZS' |
216 | | 'VEF' |
217 | | 'VES' |
218 | | 'VND' |
219 | | 'VUV' |
220 | | 'WST' |
221 | | 'XAF' |
222 | | 'XCD' |
223 | | 'XOF' |
224 | | 'XPF' |
225 | | 'YER' |
226 | | 'ZAR' |
227 | | 'ZMW' |
228 | | 'ZMK' |
229 | | 'ZWD' |
230 | XeroNetworkKey?: string |
231 | SalesDefaultAccountCode?: string |
232 | PurchasesDefaultAccountCode?: string |
233 | SalesTrackingCategories?: { |
234 | TrackingCategoryName?: string |
235 | TrackingOptionName?: string |
236 | }[] |
237 | PurchasesTrackingCategories?: { |
238 | TrackingCategoryName?: string |
239 | TrackingOptionName?: string |
240 | }[] |
241 | TrackingCategoryName?: string |
242 | TrackingCategoryOption?: string |
243 | PaymentTerms?: { |
244 | Bills?: { |
245 | Day?: number |
246 | Type?: |
247 | | 'DAYSAFTERBILLDATE' |
248 | | 'DAYSAFTERBILLMONTH' |
249 | | 'OFCURRENTMONTH' |
250 | | 'OFFOLLOWINGMONTH' |
251 | } |
252 | Sales?: { |
253 | Day?: number |
254 | Type?: |
255 | | 'DAYSAFTERBILLDATE' |
256 | | 'DAYSAFTERBILLMONTH' |
257 | | 'OFCURRENTMONTH' |
258 | | 'OFFOLLOWINGMONTH' |
259 | } |
260 | } |
261 | UpdatedDateUTC?: string |
262 | ContactGroups?: { |
263 | Name?: string |
264 | Status?: 'ACTIVE' | 'DELETED' |
265 | ContactGroupID?: string |
266 | Contacts?: {}[] |
267 | }[] |
268 | Website?: string |
269 | BrandingTheme?: { |
270 | BrandingThemeID?: string |
271 | Name?: string |
272 | LogoUrl?: string |
273 | Type?: 'INVOICE' |
274 | SortOrder?: number |
275 | CreatedDateUTC?: string |
276 | } |
277 | BatchPayments?: { |
278 | BankAccountNumber?: string |
279 | BankAccountName?: string |
280 | Details?: string |
281 | Code?: string |
282 | Reference?: string |
283 | } |
284 | Discount?: number |
285 | Balances?: { |
286 | AccountsReceivable?: { Outstanding?: number; Overdue?: number } |
287 | AccountsPayable?: { Outstanding?: number; Overdue?: number } |
288 | } |
289 | Attachments?: { |
290 | AttachmentID?: string |
291 | FileName?: string |
292 | Url?: string |
293 | MimeType?: string |
294 | ContentLength?: number |
295 | IncludeOnline?: false | true |
296 | }[] |
297 | HasAttachments?: never |
298 | ValidationErrors?: { Message?: string }[] |
299 | HasValidationErrors?: never |
300 | StatusAttributeString?: string |
301 | } |
302 | LineItems?: { |
303 | LineItemID?: string |
304 | Description?: string |
305 | Quantity?: number |
306 | UnitAmount?: number |
307 | ItemCode?: string |
308 | AccountCode?: string |
309 | AccountID?: string |
310 | TaxType?: string |
311 | TaxAmount?: number |
312 | Item?: { Code?: string; Name?: string; ItemID?: string } |
313 | LineAmount?: number |
314 | Tracking?: { |
315 | TrackingCategoryID?: string |
316 | TrackingOptionID?: string |
317 | Name?: string |
318 | Option?: string |
319 | }[] |
320 | DiscountRate?: number |
321 | DiscountAmount?: number |
322 | RepeatingInvoiceID?: string |
323 | Taxability?: 'TAXABLE' | 'NON_TAXABLE' | 'EXEMPT' | 'PART_TAXABLE' | 'NOT_APPLICABLE' |
324 | SalesTaxCodeId?: number |
325 | TaxBreakdown?: { |
326 | TaxComponentId?: string |
327 | Type?: |
328 | | 'SYSGST/USCOUNTRY' |
329 | | 'SYSGST/USSTATE' |
330 | | 'SYSGST/USCOUNTY' |
331 | | 'SYSGST/USCITY' |
332 | | 'SYSGST/USSPECIAL' |
333 | Name?: string |
334 | TaxPercentage?: number |
335 | TaxAmount?: number |
336 | TaxableAmount?: number |
337 | NonTaxableAmount?: number |
338 | ExemptAmount?: number |
339 | StateAssignedNo?: string |
340 | JurisdictionRegion?: string |
341 | }[] |
342 | }[] |
343 | User?: { |
344 | UserID?: string |
345 | EmailAddress?: string |
346 | FirstName?: string |
347 | LastName?: string |
348 | UpdatedDateUTC?: string |
349 | IsSubscriber?: false | true |
350 | OrganisationRole?: |
351 | | 'READONLY' |
352 | | 'INVOICEONLY' |
353 | | 'STANDARD' |
354 | | 'FINANCIALADVISER' |
355 | | 'MANAGEDCLIENT' |
356 | | 'CASHBOOKCLIENT' |
357 | | 'UNKNOWN' |
358 | } |
359 | Reference?: string |
360 | LineAmountTypes?: 'Exclusive' | 'Inclusive' | 'NoTax' |
361 | SubTotal?: number |
362 | TotalTax?: number |
363 | Total?: number |
364 | ReceiptID?: string |
365 | Status?: 'DRAFT' | 'SUBMITTED' | 'AUTHORISED' | 'DECLINED' | 'VOIDED' |
366 | ReceiptNumber?: string |
367 | UpdatedDateUTC?: string |
368 | HasAttachments?: never |
369 | Url?: string |
370 | ValidationErrors?: { Message?: string }[] |
371 | Warnings?: { Message?: string }[] |
372 | Attachments?: { |
373 | AttachmentID?: string |
374 | FileName?: string |
375 | Url?: string |
376 | MimeType?: string |
377 | ContentLength?: number |
378 | IncludeOnline?: false | true |
379 | }[] |
380 | }[] |
381 | } |
382 | ) { |
383 | const url = new URL(`https://api.xero.com/api.xro/2.0/Receipts/${ReceiptID}`) |
384 | for (const [k, v] of [['unitdp', unitdp]]) { |
385 | if (v !== undefined && v !== '' && k !== undefined) { |
386 | url.searchParams.append(k, v) |
387 | } |
388 | } |
389 | const response = await fetch(url, { |
390 | method: 'POST', |
391 | headers: { |
392 | Accept: 'application/json', |
393 | 'xero-tenant-id': xero_tenant_id, |
394 | 'Idempotency-Key': Idempotency_Key, |
395 | 'Content-Type': 'application/json', |
396 | Authorization: 'Bearer ' + auth.token |
397 | }, |
398 | body: JSON.stringify(body) |
399 | }) |
400 | if (!response.ok) { |
401 | const text = await response.text() |
402 | throw new Error(`${response.status} ${text}`) |
403 | } |
404 | return await response.json() |
405 | } |
406 |
|