0

Update a discount added to a deal

by
Published Oct 17, 2025

Edits a discount added to a deal, changing the deal value if the deal has one-time products attached.

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 discount added to a deal
7
 * Edits a discount added to a deal, changing the deal value if the deal has one-time products attached.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  id: string,
12
  discount_id: string,
13
  body: {
14
    description?: string;
15
    amount?: number;
16
    type?: "percentage" | "amount";
17
  },
18
) {
19
  const url = new URL(
20
    `https://api.pipedrive.com/api/v2/deals/${id}/discounts/${discount_id}`,
21
  );
22

23
  const response = await fetch(url, {
24
    method: "PATCH",
25
    headers: {
26
      "Content-Type": "application/json",
27
      "x-api-token": auth.apiToken,
28
    },
29
    body: JSON.stringify(body),
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37