0

Update pricebook

by
Published Oct 17, 2025

update existing pricebook.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Update pricebook
7
 * update existing pricebook.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  pricebook_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    name: string;
15
    description?: string;
16
    currency_id: string;
17
    pricebook_type: string;
18
    is_increase: false | true;
19
    rounding_type?: string;
20
    pricebook_items?: {
21
      item_id?: number;
22
      pricebook_rate?: number;
23
      pricebook_item_id?: number;
24
    }[];
25
    sales_or_purchase_type: string;
26
  },
27
) {
28
  const url = new URL(
29
    `https://www.zohoapis.com/inventory/v1/pricebooks/${pricebook_id}`,
30
  );
31
  for (const [k, v] of [["organization_id", organization_id]]) {
32
    if (v !== undefined && v !== "" && k !== undefined) {
33
      url.searchParams.append(k, v);
34
    }
35
  }
36
  const response = await fetch(url, {
37
    method: "PUT",
38
    headers: {
39
      "Content-Type": "application/json",
40
      Authorization: "Zoho-oauthtoken " + auth.token,
41
    },
42
    body: JSON.stringify(body),
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50