1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Updating a composite item |
7 | * Updating details of an existing composite item. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | composite_item_id: string, |
12 | organization_id: string | undefined, |
13 | body: { |
14 | composite_item_id?: number; |
15 | name: string; |
16 | unit?: string; |
17 | tax_id?: number; |
18 | description?: string; |
19 | tax_name?: string; |
20 | tax_percentage?: number; |
21 | tax_type?: string; |
22 | purchase_account_id?: number; |
23 | purchase_account_name?: string; |
24 | account_id?: number; |
25 | account_name?: string; |
26 | inventory_account_id?: number; |
27 | inventory_account_name?: string; |
28 | status?: string; |
29 | source?: string; |
30 | is_combo_product?: false | true; |
31 | item_type: string; |
32 | rate: number; |
33 | pricebook_rate?: number; |
34 | purchase_rate?: number; |
35 | reorder_level?: number; |
36 | initial_stock?: number; |
37 | initial_stock_rate?: number; |
38 | vendor_id?: number; |
39 | vendor_name?: string; |
40 | stock_on_hand?: number; |
41 | asset_value?: number; |
42 | available_stock?: number; |
43 | actual_available_stock?: number; |
44 | sku: string; |
45 | upc?: number; |
46 | ean?: number; |
47 | isbn?: number; |
48 | part_number?: string; |
49 | image_id?: number; |
50 | image_name?: string; |
51 | purchase_description?: string; |
52 | custom_fields?: { |
53 | custom_field_id?: number; |
54 | value?: string; |
55 | index?: number; |
56 | label?: string; |
57 | }[]; |
58 | mapped_items: { |
59 | line_item_id?: number; |
60 | item_id?: number; |
61 | name?: string; |
62 | rate?: number; |
63 | purchase_rate?: number; |
64 | sku?: string; |
65 | image_id?: number; |
66 | image_name?: string; |
67 | purchase_description?: string; |
68 | image_type?: string; |
69 | unit?: string; |
70 | is_combo_product?: false | true; |
71 | description?: string; |
72 | quantity?: number; |
73 | stock_on_hand?: number; |
74 | available_stock?: number; |
75 | actual_available_stock?: number; |
76 | }[]; |
77 | item_tax_preferences?: { tax_id?: number; tax_specification?: string }[]; |
78 | hsn_or_sac?: string; |
79 | product_type: string; |
80 | }, |
81 | ) { |
82 | const url = new URL( |
83 | `https://www.zohoapis.com/inventory/v1/compositeitems/${composite_item_id}`, |
84 | ); |
85 | for (const [k, v] of [["organization_id", organization_id]]) { |
86 | if (v !== undefined && v !== "" && k !== undefined) { |
87 | url.searchParams.append(k, v); |
88 | } |
89 | } |
90 | const response = await fetch(url, { |
91 | method: "PUT", |
92 | headers: { |
93 | "Content-Type": "application/json", |
94 | Authorization: "Zoho-oauthtoken " + auth.token, |
95 | }, |
96 | body: JSON.stringify(body), |
97 | }); |
98 | if (!response.ok) { |
99 | const text = await response.text(); |
100 | throw new Error(`${response.status} ${text}`); |
101 | } |
102 | return await response.json(); |
103 | } |
104 |
|