Updates a superfund

Update properties on a single Superfund

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 superfund
7
 * Update properties on a single Superfund
8
 */
9
export async function main(
10
	auth: Xero,
11
	SuperFundID: string,
12
	Xero_Tenant_Id: string,
13
	Idempotency_Key: string,
14
	body: {
15
		SuperFundID?: string
16
		Type: 'REGULATED' | 'SMSF'
17
		Name?: string
18
		ABN?: string
19
		BSB?: string
20
		AccountNumber?: string
21
		AccountName?: string
22
		ElectronicServiceAddress?: string
23
		EmployerNumber?: string
24
		SPIN?: string
25
		USI?: string
26
		UpdatedDateUTC?: string
27
		ValidationErrors?: { Message?: string }[]
28
	}[]
29
) {
30
	const url = new URL(`https://api.xero.com/payroll.xro/1.0/Superfunds/${SuperFundID}`)
31

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