1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Sell fixed asset |
7 | * Sell the fixed asset. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | fixed_asset_id: string, |
12 | organization_id: string | undefined, |
13 | body: { |
14 | expense_account_id: string; |
15 | invoice_id: string; |
16 | line_item_id: string; |
17 | reason: string; |
18 | }, |
19 | ) { |
20 | const url = new URL( |
21 | `https://www.zohoapis.com/books/v3/fixedassets/${fixed_asset_id}/sell`, |
22 | ); |
23 | for (const [k, v] of [["organization_id", organization_id]]) { |
24 | if (v !== undefined && v !== "" && k !== undefined) { |
25 | url.searchParams.append(k, v); |
26 | } |
27 | } |
28 | const response = await fetch(url, { |
29 | method: "POST", |
30 | headers: { |
31 | "Content-Type": "application/json", |
32 | Authorization: "Zoho-oauthtoken " + 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 |
|