1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create a transfer order |
7 | * Creates a new transfer order in Zoho Inventory. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | organization_id: string | undefined, |
12 | ignore_auto_number_generation: string | undefined, |
13 | body: { |
14 | transfer_order_number: string; |
15 | date: string; |
16 | from_location_id: string; |
17 | to_location_id: string; |
18 | line_items: { |
19 | item_id: number; |
20 | name: string; |
21 | description?: string; |
22 | quantity_transfer: number; |
23 | unit?: string; |
24 | }[]; |
25 | is_intransit_order?: false | true; |
26 | }, |
27 | ) { |
28 | const url = new URL(`https://www.zohoapis.com/inventory/v1/transferorders`); |
29 | for (const [k, v] of [ |
30 | ["organization_id", organization_id], |
31 | ["ignore_auto_number_generation", ignore_auto_number_generation], |
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 |
|