1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates a new deduction for a specific employee |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | Xero_Tenant_Id: string, |
12 | Idempotency_Key: string, |
13 | body: { |
14 | deductionId?: string |
15 | deductionName: string |
16 | deductionCategory: |
17 | | 'PayrollGiving' |
18 | | 'KiwiSaverVoluntaryContributions' |
19 | | 'Superannuation' |
20 | | 'NzOther' |
21 | liabilityAccountId: string |
22 | currentRecord?: false | true |
23 | standardAmount?: number |
24 | } |
25 | ) { |
26 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Deductions`) |
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 |
|