0

Updating a package

by
Published Oct 17, 2025

Updating details of existing package.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Updating a package
7
 * Updating details of existing package.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  package_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    package_number?: string;
15
    date: string;
16
    custom_fields?: { customfield_id?: number; value?: string }[];
17
    line_items: {
18
      line_item_id?: number;
19
      so_line_item_id?: number;
20
      quantity?: number;
21
    }[];
22
    notes?: string;
23
  },
24
) {
25
  const url = new URL(
26
    `https://www.zohoapis.com/inventory/v1/packages/${package_id}`,
27
  );
28
  for (const [k, v] of [["organization_id", organization_id]]) {
29
    if (v !== undefined && v !== "" && k !== undefined) {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "PUT",
35
    headers: {
36
      "Content-Type": "application/json",
37
      Authorization: "Zoho-oauthtoken " + auth.token,
38
    },
39
    body: JSON.stringify(body),
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47