0

Add a product to a deal

by
Published Oct 17, 2025

Adds a product to a deal, creating a new item called a deal-product.

Script pipedrive Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Pipedrive = {
3
  apiToken: string;
4
};
5
/**
6
 * Add a product to a deal
7
 * Adds a product to a deal, creating a new item called a deal-product.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  id: string,
12
  body: {
13
    product_id: number;
14
    item_price: number;
15
    quantity: number;
16
    tax?: number;
17
    comments?: string;
18
    discount?: number;
19
    is_enabled?: false | true;
20
    tax_method?: "exclusive" | "inclusive" | "none";
21
    discount_type?: "percentage" | "amount";
22
    product_variation_id?: number;
23
  } & {
24
    billing_frequency?:
25
      | "one-time"
26
      | "annually"
27
      | "semi-annually"
28
      | "quarterly"
29
      | "monthly"
30
      | "weekly";
31
  } & { billing_frequency_cycles?: number } & { billing_start_date?: string },
32
) {
33
  const url = new URL(`https://api.pipedrive.com/api/v2/deals/${id}/products`);
34

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