1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update an item adjustment |
7 | * Update the details of an existing item adjustment by quantity. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | inventory_adjustment_id: string, |
12 | organization_id: string | undefined, |
13 | body: { |
14 | date: string; |
15 | reason: string; |
16 | description?: string; |
17 | reference_number?: string; |
18 | adjustment_type: "quantity"; |
19 | location_id?: string; |
20 | line_items: { |
21 | line_item_id?: number; |
22 | item_id: number; |
23 | name?: string; |
24 | description?: string; |
25 | quantity_adjusted: number; |
26 | item_total?: number; |
27 | unit?: string; |
28 | is_combo_product?: false | true; |
29 | adjustment_account_id?: number; |
30 | adjustment_account_name?: string; |
31 | location_id?: string; |
32 | }[]; |
33 | }, |
34 | ) { |
35 | const url = new URL( |
36 | `https://www.zohoapis.com/inventory/v1/inventoryadjustments/${inventory_adjustment_id}`, |
37 | ); |
38 | for (const [k, v] of [["organization_id", organization_id]]) { |
39 | if (v !== undefined && v !== "" && k !== undefined) { |
40 | url.searchParams.append(k, v); |
41 | } |
42 | } |
43 | const response = await fetch(url, { |
44 | method: "PUT", |
45 | headers: { |
46 | "Content-Type": "application/json", |
47 | Authorization: "Zoho-oauthtoken " + auth.token, |
48 | }, |
49 | body: JSON.stringify(body), |
50 | }); |
51 | if (!response.ok) { |
52 | const text = await response.text(); |
53 | throw new Error(`${response.status} ${text}`); |
54 | } |
55 | return await response.json(); |
56 | } |
57 |
|