0

Update a fixed asset

by
Published Oct 17, 2025

Updates the fixed asset with given information.

Script zoho Verified

The script

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