1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates a history record for a specific bank transactions |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | BankTransactionID: string, |
12 | xero_tenant_id: string, |
13 | Idempotency_Key: string, |
14 | body: { |
15 | HistoryRecords?: { |
16 | Details?: string |
17 | Changes?: string |
18 | User?: string |
19 | DateUTC?: string |
20 | }[] |
21 | } |
22 | ) { |
23 | const url = new URL( |
24 | `https://api.xero.com/api.xro/2.0/BankTransactions/${BankTransactionID}/History` |
25 | ) |
26 |
|
27 | const response = await fetch(url, { |
28 | method: 'PUT', |
29 | headers: { |
30 | Accept: 'application/json', |
31 | 'xero-tenant-id': xero_tenant_id, |
32 | 'Idempotency-Key': Idempotency_Key, |
33 | 'Content-Type': 'application/json', |
34 | Authorization: 'Bearer ' + auth.token |
35 | }, |
36 | body: JSON.stringify(body) |
37 | }) |
38 | if (!response.ok) { |
39 | const text = await response.text() |
40 | throw new Error(`${response.status} ${text}`) |
41 | } |
42 | return await response.json() |
43 | } |
44 |
|