1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a Sales Return Receive |
7 | * Creating a sales return receive to mark the receivable goods as received. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | salesreturn_id: string | undefined, |
13 | body: { |
14 | date?: string; |
15 | line_items: { line_item_id?: {}; quantity?: number }[]; |
16 | notes?: string; |
17 | }, |
18 | ) { |
19 | const url = new URL( |
20 | `https://www.zohoapis.com/inventory/v1/salesreturnreceives`, |
21 | ); |
22 | for (const [k, v] of [ |
23 | ["organization_id", organization_id], |
24 | ["salesreturn_id", salesreturn_id], |
25 | ]) { |
26 | if (v !== undefined && v !== "" && k !== undefined) { |
27 | url.searchParams.append(k, v); |
28 | } |
29 | } |
30 | const response = await fetch(url, { |
31 | method: "POST", |
32 | headers: { |
33 | "Content-Type": "application/json", |
34 | Authorization: "Zoho-oauthtoken " + auth.token, |
35 | }, |
36 | body: JSON.stringify(body), |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.json(); |
43 | } |
44 |
|