Updates a specific employee's earnings template records

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
 * Updates a specific employee's earnings template records
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	EmployeeID: string,
12
	PayTemplateEarningID: string,
13
	Xero_Tenant_Id: string,
14
	Idempotency_Key: string,
15
	body: {
16
		payTemplateEarningID?: string
17
		ratePerUnit?: number
18
		numberOfUnits?: number
19
		fixedAmount?: number
20
		earningsRateID?: string
21
		name?: string
22
	}
23
) {
24
	const url = new URL(
25
		`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/PayTemplates/earnings/${PayTemplateEarningID}`
26
	)
27

28
	const response = await fetch(url, {
29
		method: 'PUT',
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