0

Get all deals

by
Published Oct 17, 2025

Returns data about all not archived deals.

Script pipedrive Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Pipedrive = {
3
  apiToken: string;
4
};
5
/**
6
 * Get all deals
7
 * Returns data about all not archived deals.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  filter_id: string | undefined,
12
  ids: string | undefined,
13
  owner_id: string | undefined,
14
  person_id: string | undefined,
15
  org_id: string | undefined,
16
  pipeline_id: string | undefined,
17
  stage_id: string | undefined,
18
  status: "open" | "won" | "lost" | "deleted" | undefined,
19
  updated_since: string | undefined,
20
  updated_until: string | undefined,
21
  sort_by: "id" | "update_time" | "add_time" | undefined,
22
  sort_direction: "asc" | "desc" | undefined,
23
  include_fields:
24
    | "next_activity_id"
25
    | "last_activity_id"
26
    | "first_won_time"
27
    | "products_count"
28
    | "files_count"
29
    | "notes_count"
30
    | "followers_count"
31
    | "email_messages_count"
32
    | "activities_count"
33
    | "done_activities_count"
34
    | "undone_activities_count"
35
    | "participants_count"
36
    | "last_incoming_mail_time"
37
    | "last_outgoing_mail_time"
38
    | undefined,
39
  custom_fields: string | undefined,
40
  limit: string | undefined,
41
  cursor: string | undefined,
42
) {
43
  const url = new URL(`https://api.pipedrive.com/api/v2/deals`);
44
  for (const [k, v] of [
45
    ["filter_id", filter_id],
46
    ["ids", ids],
47
    ["owner_id", owner_id],
48
    ["person_id", person_id],
49
    ["org_id", org_id],
50
    ["pipeline_id", pipeline_id],
51
    ["stage_id", stage_id],
52
    ["status", status],
53
    ["updated_since", updated_since],
54
    ["updated_until", updated_until],
55
    ["sort_by", sort_by],
56
    ["sort_direction", sort_direction],
57
    ["include_fields", include_fields],
58
    ["custom_fields", custom_fields],
59
    ["limit", limit],
60
    ["cursor", cursor],
61
  ]) {
62
    if (v !== undefined && v !== "" && k !== undefined) {
63
      url.searchParams.append(k, v);
64
    }
65
  }
66
  const response = await fetch(url, {
67
    method: "GET",
68
    headers: {
69
      "x-api-token": auth.apiToken,
70
    },
71
    body: undefined,
72
  });
73
  if (!response.ok) {
74
    const text = await response.text();
75
    throw new Error(`${response.status} ${text}`);
76
  }
77
  return await response.json();
78
}
79