Creates an employee working pattern

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 an employee working pattern
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
		effectiveFrom: string
16
		workingWeeks: {
17
			monday: number
18
			tuesday: number
19
			wednesday: number
20
			thursday: number
21
			friday: number
22
			saturday: number
23
			sunday: number
24
		}[]
25
	}
26
) {
27
	const url = new URL(
28
		`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/Working-Patterns`
29
	)
30

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