Creates a new employee benefit

Script xero Verified

by hugo697 ยท 12/20/2024

The script

Submitted by hugo697 Bun
Verified 515 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Creates a new employee benefit
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: 'StakeholderPension' | 'Other'
17
		liabilityAccountId: string
18
		expenseAccountId: string
19
		standardAmount?: number
20
		percentage: number
21
		calculationType: 'FixedAmount' | 'PercentageOfGross'
22
		currentRecord?: false | true
23
		subjectToNIC?: false | true
24
		subjectToPension?: false | true
25
		subjectToTax?: false | true
26
		isCalculatingOnQualifyingEarnings?: false | true
27
		showBalanceToEmployee?: false | true
28
	}
29
) {
30
	const url = new URL(`https://api.xero.com/payroll.xro/2.0/Benefits`)
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