Creates a salary and wage record for a specific employee

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 salary and wage record for a specific 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
		salaryAndWagesID?: string
16
		earningsRateID: string
17
		numberOfUnitsPerWeek: number
18
		ratePerUnit?: number
19
		numberOfUnitsPerDay?: number
20
		effectiveFrom: string
21
		annualSalary: number
22
		status: 'Active' | 'Pending' | 'History'
23
		paymentType: 'Salary' | 'Hourly'
24
	}
25
) {
26
	const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/SalaryAndWages`)
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