1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update an item |
7 | * Update the details of an item. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | item_id: string, |
12 | organization_id: string | undefined, |
13 | body: { |
14 | group_id?: string; |
15 | group_name?: string; |
16 | unit?: string; |
17 | item_type?: string; |
18 | product_type?: string; |
19 | is_taxable?: false | true; |
20 | tax_id?: number; |
21 | description?: string; |
22 | tax_name?: string; |
23 | tax_percentage?: number; |
24 | tax_type?: string; |
25 | purchase_account_id?: number; |
26 | purchase_account_name?: string; |
27 | account_name?: string; |
28 | inventory_account_id?: number; |
29 | attribute_id1?: number; |
30 | attribute_name1?: string; |
31 | status?: string; |
32 | source?: string; |
33 | name: string; |
34 | rate?: number; |
35 | pricebook_rate?: number; |
36 | purchase_rate?: number; |
37 | reorder_level?: number; |
38 | locations?: { |
39 | location_id?: string; |
40 | initial_stock?: number; |
41 | initial_stock_rate?: number; |
42 | }[]; |
43 | vendor_id?: number; |
44 | vendor_name?: string; |
45 | sku?: string; |
46 | upc?: number; |
47 | ean?: number; |
48 | isbn?: string; |
49 | part_number?: string; |
50 | attribute_option_id1?: number; |
51 | attribute_option_name1?: number; |
52 | image_id?: number; |
53 | image_name?: string; |
54 | purchase_description?: string; |
55 | image_type?: string; |
56 | item_tax_preferences?: { tax_id?: number; tax_specification?: string }[]; |
57 | hsn_or_sac?: string; |
58 | sat_item_key_code?: string; |
59 | unitkey_code?: string; |
60 | custom_fields?: { customfield_id?: number; value?: string }[]; |
61 | }, |
62 | ) { |
63 | const url = new URL(`https://www.zohoapis.com/inventory/v1/items/${item_id}`); |
64 | for (const [k, v] of [["organization_id", organization_id]]) { |
65 | if (v !== undefined && v !== "" && k !== undefined) { |
66 | url.searchParams.append(k, v); |
67 | } |
68 | } |
69 | const response = await fetch(url, { |
70 | method: "PUT", |
71 | headers: { |
72 | "Content-Type": "application/json", |
73 | Authorization: "Zoho-oauthtoken " + auth.token, |
74 | }, |
75 | body: JSON.stringify(body), |
76 | }); |
77 | if (!response.ok) { |
78 | const text = await response.text(); |
79 | throw new Error(`${response.status} ${text}`); |
80 | } |
81 | return await response.json(); |
82 | } |
83 |
|