Creates a new leave type

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 leave type
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	Xero_Tenant_Id: string,
12
	Idempotency_Key: string,
13
	body: {
14
		leaveID?: string
15
		leaveTypeID?: string
16
		name: string
17
		isPaidLeave: false | true
18
		showOnPayslip: false | true
19
		updatedDateUTC?: string
20
		isActive?: false | true
21
		isStatutoryLeave?: false | true
22
	}
23
) {
24
	const url = new URL(`https://api.xero.com/payroll.xro/2.0/LeaveTypes`)
25

26
	const response = await fetch(url, {
27
		method: 'POST',
28
		headers: {
29
			Accept: 'application/json',
30
			'Xero-Tenant-Id': Xero_Tenant_Id,
31
			'Idempotency-Key': Idempotency_Key,
32
			'Content-Type': 'application/json',
33
			Authorization: 'Bearer ' + auth.token
34
		},
35
		body: JSON.stringify(body)
36
	})
37
	if (!response.ok) {
38
		const text = await response.text()
39
		throw new Error(`${response.status} ${text}`)
40
	}
41
	return await response.json()
42
}
43