0

Creates a leave set-up for a specific employee. This is required before viewing, configuring and requesting leave for an employee

by
Published Dec 20, 2024
Script xero Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Creates a leave set-up for a specific employee. This is required before viewing, configuring and requesting leave for an employee
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	EmployeeID: string,
12
	Xero_Tenant_Id: string,
13
	Idempotency_Key: string,
14
	body: {
15
		includeHolidayPay?: false | true
16
		holidayPayOpeningBalance?: number
17
		annualLeaveOpeningBalance?: number
18
		negativeAnnualLeaveBalancePaidAmount?: number
19
		sickLeaveHoursToAccrueAnnually?: number
20
		sickLeaveMaximumHoursToAccrue?: number
21
		sickLeaveOpeningBalance?: number
22
		SickLeaveScheduleOfAccrual?: string
23
		SickLeaveAnniversaryDate?: string
24
	}
25
) {
26
	const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/LeaveSetup`)
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