0

Update a deal

by
Published Oct 17, 2025

Updates the properties of 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 a deal
7
 * Updates the properties of a deal.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  id: string,
12
  body: {
13
    title?: string;
14
    owner_id?: number;
15
    person_id?: number;
16
    org_id?: number;
17
    pipeline_id?: number;
18
    stage_id?: number;
19
    value?: number;
20
    currency?: string;
21
    add_time?: string;
22
    update_time?: string;
23
    stage_change_time?: string;
24
    is_deleted?: false | true;
25
    status?: string;
26
    probability?: number;
27
    lost_reason?: string;
28
    visible_to?: number;
29
    close_time?: string;
30
    won_time?: string;
31
    lost_time?: string;
32
    expected_close_date?: string;
33
    label_ids?: number[];
34
  },
35
) {
36
  const url = new URL(`https://api.pipedrive.com/api/v2/deals/${id}`);
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