0

Get details of a deal

by
Published Oct 17, 2025

Returns the details of a specific 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
 * Get details of a deal
7
 * Returns the details of a specific deal.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  id: string,
12
  include_fields:
13
    | "next_activity_id"
14
    | "last_activity_id"
15
    | "first_won_time"
16
    | "products_count"
17
    | "files_count"
18
    | "notes_count"
19
    | "followers_count"
20
    | "email_messages_count"
21
    | "activities_count"
22
    | "done_activities_count"
23
    | "undone_activities_count"
24
    | "participants_count"
25
    | "last_incoming_mail_time"
26
    | "last_outgoing_mail_time"
27
    | undefined,
28
  custom_fields: string | undefined,
29
) {
30
  const url = new URL(`https://api.pipedrive.com/api/v2/deals/${id}`);
31
  for (const [k, v] of [
32
    ["include_fields", include_fields],
33
    ["custom_fields", custom_fields],
34
  ]) {
35
    if (v !== undefined && v !== "" && k !== undefined) {
36
      url.searchParams.append(k, v);
37
    }
38
  }
39
  const response = await fetch(url, {
40
    method: "GET",
41
    headers: {
42
      "x-api-token": auth.apiToken,
43
    },
44
    body: undefined,
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