1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates a new superannuation |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | Xero_Tenant_Id: string, |
12 | Idempotency_Key: string, |
13 | body: { |
14 | id?: string |
15 | name: string |
16 | category: 'KiwiSaver' | 'ComplyingFund' | 'Other' |
17 | liabilityAccountId: string |
18 | expenseAccountId: string |
19 | calculationTypeNZ?: 'FixedAmount' | 'PercentageOfTaxableEarnings' |
20 | standardAmount?: number |
21 | percentage?: number |
22 | companyMax?: number |
23 | currentRecord?: false | true |
24 | } |
25 | ) { |
26 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Superannuations`) |
27 |
|
28 | const response = await fetch(url, { |
29 | method: 'POST', |
30 | headers: { |
31 | Accept: 'application/json', |
32 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
33 | 'Idempotency-Key': Idempotency_Key, |
34 | 'Content-Type': 'application/json', |
35 | Authorization: 'Bearer ' + auth.token |
36 | }, |
37 | body: JSON.stringify(body) |
38 | }) |
39 | if (!response.ok) { |
40 | const text = await response.text() |
41 | throw new Error(`${response.status} ${text}`) |
42 | } |
43 | return await response.json() |
44 | } |
45 |
|