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

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