1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Create tracking categories |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | xero_tenant_id: string, |
12 | Idempotency_Key: string, |
13 | body: { |
14 | TrackingCategoryID?: string |
15 | TrackingOptionID?: string |
16 | Name?: string |
17 | Option?: string |
18 | Status?: 'ACTIVE' | 'ARCHIVED' | 'DELETED' |
19 | Options?: { |
20 | TrackingOptionID?: string |
21 | Name?: string |
22 | Status?: 'ACTIVE' | 'ARCHIVED' | 'DELETED' |
23 | TrackingCategoryID?: string |
24 | }[] |
25 | } |
26 | ) { |
27 | const url = new URL(`https://api.xero.com/api.xro/2.0/TrackingCategories`) |
28 |
|
29 | const response = await fetch(url, { |
30 | method: 'PUT', |
31 | headers: { |
32 | Accept: 'application/json', |
33 | 'xero-tenant-id': xero_tenant_id, |
34 | 'Idempotency-Key': Idempotency_Key, |
35 | 'Content-Type': 'application/json', |
36 | Authorization: 'Bearer ' + auth.token |
37 | }, |
38 | body: JSON.stringify(body) |
39 | }) |
40 | if (!response.ok) { |
41 | const text = await response.text() |
42 | throw new Error(`${response.status} ${text}`) |
43 | } |
44 | return await response.json() |
45 | } |
46 |
|