0

Creating a package

by
Published Oct 17, 2025

A new package can be created. To create package, URL parameter salesorder_id also needed.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Creating a package
7
 * A new package can be created. To create package, URL parameter salesorder_id also needed.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  organization_id: string | undefined,
12
  salesorder_id: string | undefined,
13
  body: {
14
    package_number?: string;
15
    date: string;
16
    custom_fields?: { customfield_id?: number; value?: string }[];
17
    line_items: { so_line_item_id?: number; quantity?: number }[];
18
    notes?: string;
19
  },
20
) {
21
  const url = new URL(`https://www.zohoapis.com/inventory/v1/packages`);
22
  for (const [k, v] of [
23
    ["organization_id", organization_id],
24
    ["salesorder_id", salesorder_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