0

Update a product

by
Published Oct 17, 2025

Updates product data.

Script pipedrive Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Pipedrive = {
3
  apiToken: string;
4
};
5
/**
6
 * Update a product
7
 * Updates product data.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  id: string,
12
  body: { name?: string } & {
13
    code?: string;
14
    description?: string;
15
    unit?: string;
16
    tax?: number;
17
    category?: number;
18
    owner_id?: number;
19
    is_linkable?: false | true;
20
    visible_to?: 1 | 3 | 5 | 7;
21
    prices?: {}[];
22
  } & {
23
    billing_frequency?:
24
      | "one-time"
25
      | "annually"
26
      | "semi-annually"
27
      | "quarterly"
28
      | "monthly"
29
      | "weekly";
30
  } & { billing_frequency_cycles?: number },
31
) {
32
  const url = new URL(`https://api.pipedrive.com/api/v2/products/${id}`);
33

34
  const response = await fetch(url, {
35
    method: "PATCH",
36
    headers: {
37
      "Content-Type": "application/json",
38
      "x-api-token": auth.apiToken,
39
    },
40
    body: JSON.stringify(body),
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48