0

Get all persons

by
Published Oct 17, 2025

Returns data about all persons. Fields `ims`, `postal_address`, `notes`, `birthday`, and `job_title` are only included if contact sync is enabled for the company.

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 persons
7
 * Returns data about all persons. Fields `ims`, `postal_address`, `notes`, `birthday`, and `job_title` are only included if contact sync is enabled for the company.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  filter_id: string | undefined,
12
  ids: string | undefined,
13
  owner_id: string | undefined,
14
  org_id: string | undefined,
15
  updated_since: string | undefined,
16
  updated_until: string | undefined,
17
  sort_by: "id" | "update_time" | "add_time" | undefined,
18
  sort_direction: "asc" | "desc" | undefined,
19
  include_fields:
20
    | "next_activity_id"
21
    | "last_activity_id"
22
    | "open_deals_count"
23
    | "related_open_deals_count"
24
    | "closed_deals_count"
25
    | "related_closed_deals_count"
26
    | "participant_open_deals_count"
27
    | "participant_closed_deals_count"
28
    | "email_messages_count"
29
    | "activities_count"
30
    | "done_activities_count"
31
    | "undone_activities_count"
32
    | "files_count"
33
    | "notes_count"
34
    | "followers_count"
35
    | "won_deals_count"
36
    | "related_won_deals_count"
37
    | "lost_deals_count"
38
    | "related_lost_deals_count"
39
    | "last_incoming_mail_time"
40
    | "last_outgoing_mail_time"
41
    | "marketing_status"
42
    | "doi_status"
43
    | undefined,
44
  custom_fields: string | undefined,
45
  limit: string | undefined,
46
  cursor: string | undefined,
47
) {
48
  const url = new URL(`https://api.pipedrive.com/api/v2/persons`);
49
  for (const [k, v] of [
50
    ["filter_id", filter_id],
51
    ["ids", ids],
52
    ["owner_id", owner_id],
53
    ["org_id", org_id],
54
    ["updated_since", updated_since],
55
    ["updated_until", updated_until],
56
    ["sort_by", sort_by],
57
    ["sort_direction", sort_direction],
58
    ["include_fields", include_fields],
59
    ["custom_fields", custom_fields],
60
    ["limit", limit],
61
    ["cursor", cursor],
62
  ]) {
63
    if (v !== undefined && v !== "" && k !== undefined) {
64
      url.searchParams.append(k, v);
65
    }
66
  }
67
  const response = await fetch(url, {
68
    method: "GET",
69
    headers: {
70
      "x-api-token": auth.apiToken,
71
    },
72
    body: undefined,
73
  });
74
  if (!response.ok) {
75
    const text = await response.text();
76
    throw new Error(`${response.status} ${text}`);
77
  }
78
  return await response.json();
79
}
80