Updates a specific option for a specific tracking category

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 option for a specific tracking category
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	TrackingCategoryID: string,
12
	TrackingOptionID: string,
13
	xero_tenant_id: string,
14
	Idempotency_Key: string,
15
	body: {
16
		TrackingOptionID?: string
17
		Name?: string
18
		Status?: 'ACTIVE' | 'ARCHIVED' | 'DELETED'
19
		TrackingCategoryID?: string
20
	}
21
) {
22
	const url = new URL(
23
		`https://api.xero.com/api.xro/2.0/TrackingCategories/${TrackingCategoryID}/Options/${TrackingOptionID}`
24
	)
25

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