1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a fixed asset |
7 | * Create a fixed asset. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | body: { |
13 | asset_name: string; |
14 | fixed_asset_type_id: string; |
15 | asset_account_id: string; |
16 | expense_account_id?: string; |
17 | depreciation_account_id?: string; |
18 | depreciation_method?: string; |
19 | depreciation_frequency?: string; |
20 | depreciation_percentage?: number; |
21 | total_life?: number; |
22 | salvage_value?: string; |
23 | depreciation_start_date?: string; |
24 | description?: string; |
25 | asset_cost: number; |
26 | computation_type?: string; |
27 | warranty_expiry_date?: string; |
28 | asset_purchase_date: string; |
29 | serial_no?: string; |
30 | dep_start_value?: number; |
31 | notes?: string; |
32 | tags?: { tag_id?: string; tag_option_id?: string }[]; |
33 | custom_fields?: { customfield_id?: string; value?: string }[]; |
34 | }, |
35 | ) { |
36 | const url = new URL(`https://www.zohoapis.com/books/v3/fixedassets`); |
37 | for (const [k, v] of [["organization_id", organization_id]]) { |
38 | if (v !== undefined && v !== "" && k !== undefined) { |
39 | url.searchParams.append(k, v); |
40 | } |
41 | } |
42 | const response = await fetch(url, { |
43 | method: "POST", |
44 | headers: { |
45 | "Content-Type": "application/json", |
46 | Authorization: "Zoho-oauthtoken " + auth.token, |
47 | }, |
48 | body: JSON.stringify(body), |
49 | }); |
50 | if (!response.ok) { |
51 | const text = await response.text(); |
52 | throw new Error(`${response.status} ${text}`); |
53 | } |
54 | return await response.json(); |
55 | } |
56 |
|