Creates options 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
 * Creates options for 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
    TrackingOptionID?: string;
16
    Name?: string;
17
    Status?: "ACTIVE" | "ARCHIVED" | "DELETED";
18
    TrackingCategoryID?: string;
19
  },
20
) {
21
  const url = new URL(
22
    `https://api.xero.com/api.xro/2.0/TrackingCategories/${TrackingCategoryID}/Options`,
23
  );
24

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