Creates employment detail for a specific employee 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
 * Creates employment detail for a specific employee using a unique employee ID
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
		payrollCalendarID: string
16
		startDate: string
17
		employeeNumber: string
18
		niCategory: 'A' | 'B' | 'C' | 'F' | 'H' | 'I' | 'J' | 'L' | 'M' | 'S' | 'V' | 'X' | 'Z'
19
	}
20
) {
21
	const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/Employment`)
22

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