Retrieves a specific employee's summary of statutory leaves using a unique employee ID

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
 * Retrieves a specific employee's summary of statutory leaves using a unique employee ID
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	EmployeeID: string,
12
	activeOnly: string | undefined,
13
	Xero_Tenant_Id: string
14
) {
15
	const url = new URL(`https://api.xero.com/payroll.xro/2.0/StatutoryLeaves/Summary/${EmployeeID}`)
16
	for (const [k, v] of [['activeOnly', activeOnly]]) {
17
		if (v !== undefined && v !== '' && k !== undefined) {
18
			url.searchParams.append(k, v)
19
		}
20
	}
21
	const response = await fetch(url, {
22
		method: 'GET',
23
		headers: {
24
			Accept: 'application/json',
25
			'Xero-Tenant-Id': Xero_Tenant_Id,
26
			Authorization: 'Bearer ' + auth.token
27
		},
28
		body: undefined
29
	})
30
	if (!response.ok) {
31
		const text = await response.text()
32
		throw new Error(`${response.status} ${text}`)
33
	}
34
	return await response.json()
35
}
36