0

Update the product attached to a deal

by
Published Oct 17, 2025

Updates the details of the product that has been attached to a deal.

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 the product attached to a deal
7
 * Updates the details of the product that has been attached to a deal.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  id: string,
12
  product_attachment_id: string,
13
  body: {
14
    product_id?: number;
15
    item_price?: number;
16
    quantity?: number;
17
    tax?: number;
18
    comments?: string;
19
    discount?: number;
20
    is_enabled?: false | true;
21
    tax_method?: "exclusive" | "inclusive" | "none";
22
    discount_type?: "percentage" | "amount";
23
    product_variation_id?: number;
24
  } & {
25
    billing_frequency?:
26
      | "one-time"
27
      | "annually"
28
      | "semi-annually"
29
      | "quarterly"
30
      | "monthly"
31
      | "weekly";
32
  } & { billing_frequency_cycles?: number } & { billing_start_date?: string },
33
) {
34
  const url = new URL(
35
    `https://api.pipedrive.com/api/v2/deals/${id}/products/${product_attachment_id}`,
36
  );
37

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