Retrieves the opening balance 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
 * Retrieves the opening balance for a specific employee
7
 *
8
 */
9
export async function main(auth: Xero, EmployeeID: string, Xero_Tenant_Id: string) {
10
	const url = new URL(
11
		`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/OpeningBalances`
12
	)
13

14
	const response = await fetch(url, {
15
		method: 'GET',
16
		headers: {
17
			Accept: 'application/json',
18
			'Xero-Tenant-Id': Xero_Tenant_Id,
19
			Authorization: 'Bearer ' + auth.token
20
		},
21
		body: undefined
22
	})
23
	if (!response.ok) {
24
		const text = await response.text()
25
		throw new Error(`${response.status} ${text}`)
26
	}
27
	return await response.json()
28
}
29