//native
type Zoho = {
token: string;
};
/**
* Update a fixed asset
* Updates the fixed asset with given information.
*/
export async function main(
auth: Zoho,
fixed_asset_id: string,
organization_id: string | undefined,
body: {
asset_name: string;
fixed_asset_type_id: string;
asset_account_id: string;
expense_account_id?: string;
depreciation_account_id?: string;
depreciation_method?: string;
depreciation_frequency?: string;
depreciation_percentage?: number;
total_life?: number;
salvage_value?: string;
depreciation_start_date?: string;
description?: string;
asset_cost: number;
computation_type?: string;
warranty_expiry_date?: string;
asset_purchase_date: string;
serial_no?: string;
dep_start_value?: number;
notes?: string;
tags?: { tag_id?: string; tag_option_id?: string }[];
custom_fields?: { customfield_id?: string; value?: string }[];
},
) {
const url = new URL(
`https://www.zohoapis.com/books/v3/fixedassets/${fixed_asset_id}`,
);
for (const [k, v] of [["organization_id", organization_id]]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Authorization: "Zoho-oauthtoken " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago