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