1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a Sales Return |
7 | * Updation of Sales Return. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | salesreturn_id: string, |
12 | organization_id: string | undefined, |
13 | salesorder_id: string | undefined, |
14 | body: { |
15 | salesreturn_number?: string; |
16 | date?: string; |
17 | reason?: string; |
18 | custom_fields?: { customfield_id?: number; value?: string }[]; |
19 | location_id?: string; |
20 | line_items: { |
21 | line_item_id?: number; |
22 | item_id?: number; |
23 | salesorder_item_id?: number; |
24 | quantity?: number; |
25 | non_receive_quantity?: number; |
26 | location_id?: string; |
27 | }[]; |
28 | }, |
29 | ) { |
30 | const url = new URL( |
31 | `https://www.zohoapis.com/inventory/v1/salesreturns/${salesreturn_id}`, |
32 | ); |
33 | for (const [k, v] of [ |
34 | ["organization_id", organization_id], |
35 | ["salesorder_id", salesorder_id], |
36 | ]) { |
37 | if (v !== undefined && v !== "" && k !== undefined) { |
38 | url.searchParams.append(k, v); |
39 | } |
40 | } |
41 | const response = await fetch(url, { |
42 | method: "PUT", |
43 | headers: { |
44 | "Content-Type": "application/json", |
45 | Authorization: "Zoho-oauthtoken " + auth.token, |
46 | }, |
47 | body: JSON.stringify(body), |
48 | }); |
49 | if (!response.ok) { |
50 | const text = await response.text(); |
51 | throw new Error(`${response.status} ${text}`); |
52 | } |
53 | return await response.json(); |
54 | } |
55 |
|