1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Updates a specific linked transactions (billable expenses) |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | LinkedTransactionID: string, |
12 | xero_tenant_id: string, |
13 | Idempotency_Key: string, |
14 | body: { |
15 | LinkedTransactions?: { |
16 | SourceTransactionID?: string |
17 | SourceLineItemID?: string |
18 | ContactID?: string |
19 | TargetTransactionID?: string |
20 | TargetLineItemID?: string |
21 | LinkedTransactionID?: string |
22 | Status?: 'APPROVED' | 'DRAFT' | 'ONDRAFT' | 'BILLED' | 'VOIDED' |
23 | Type?: 'BILLABLEEXPENSE' |
24 | UpdatedDateUTC?: string |
25 | SourceTransactionTypeCode?: 'ACCPAY' | 'SPEND' |
26 | ValidationErrors?: { Message?: string }[] |
27 | }[] |
28 | } |
29 | ) { |
30 | const url = new URL(`https://api.xero.com/api.xro/2.0/LinkedTransactions/${LinkedTransactionID}`) |
31 |
|
32 | const response = await fetch(url, { |
33 | method: 'POST', |
34 | headers: { |
35 | Accept: 'application/json', |
36 | 'xero-tenant-id': xero_tenant_id, |
37 | 'Idempotency-Key': Idempotency_Key, |
38 | 'Content-Type': 'application/json', |
39 | Authorization: 'Bearer ' + auth.token |
40 | }, |
41 | body: JSON.stringify(body) |
42 | }) |
43 | if (!response.ok) { |
44 | const text = await response.text() |
45 | throw new Error(`${response.status} ${text}`) |
46 | } |
47 | return await response.json() |
48 | } |
49 |
|