adds a fixed asset type

Adds an fixed asset type to the system

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
 * adds a fixed asset type
7
 * Adds an fixed asset type to the system
8
 */
9
export async function main(
10
  auth: Xero,
11
  xero_tenant_id: string,
12
  Idempotency_Key: string,
13
  body: {
14
    assetTypeId?: string;
15
    assetTypeName: string;
16
    fixedAssetAccountId?: string;
17
    depreciationExpenseAccountId?: string;
18
    accumulatedDepreciationAccountId?: string;
19
    bookDepreciationSetting: {
20
      depreciationMethod?:
21
        | "NoDepreciation"
22
        | "StraightLine"
23
        | "DiminishingValue100"
24
        | "DiminishingValue150"
25
        | "DiminishingValue200"
26
        | "FullDepreciation";
27
      averagingMethod?: "FullMonth" | "ActualDays";
28
      depreciationRate?: number;
29
      effectiveLifeYears?: number;
30
      depreciationCalculationMethod?: "Rate" | "Life" | "None";
31
      depreciableObjectId?: string;
32
      depreciableObjectType?: string;
33
      bookEffectiveDateOfChangeId?: string;
34
    };
35
    locks?: number;
36
  },
37
) {
38
  const url = new URL(`https://api.xero.com/assets.xro/1.0/AssetTypes`);
39

40
  const response = await fetch(url, {
41
    method: "POST",
42
    headers: {
43
      Accept: 'application/json',
44
      "xero-tenant-id": xero_tenant_id,
45
      "Idempotency-Key": Idempotency_Key,
46
      "Content-Type": "application/json",
47
      Authorization: "Bearer " + auth.token,
48
    },
49
    body: JSON.stringify(body),
50
  });
51
  if (!response.ok) {
52
    const text = await response.text();
53
    throw new Error(`${response.status} ${text}`);
54
  }
55
  return await response.json();
56
}
57