0

Search persons

by
Published Oct 17, 2025

Searches all persons by name, email, phone, notes and/or custom fields. This endpoint is a wrapper of /v1/itemSearch with a narrower OAuth scope. Found persons can be filtered by organization ID.

Script pipedrive Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Pipedrive = {
3
  apiToken: string;
4
};
5
/**
6
 * Search persons
7
 * Searches all persons by name, email, phone, notes and/or custom fields. This endpoint is a wrapper of /v1/itemSearch with a narrower OAuth scope. Found persons can be filtered by organization ID.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  term: string | undefined,
12
  fields: "custom_fields" | "email" | "notes" | "phone" | "name" | undefined,
13
  exact_match: string | undefined,
14
  organization_id: string | undefined,
15
  include_fields: "person.picture" | undefined,
16
  limit: string | undefined,
17
  cursor: string | undefined,
18
) {
19
  const url = new URL(`https://api.pipedrive.com/api/v2/persons/search`);
20
  for (const [k, v] of [
21
    ["term", term],
22
    ["fields", fields],
23
    ["exact_match", exact_match],
24
    ["organization_id", organization_id],
25
    ["include_fields", include_fields],
26
    ["limit", limit],
27
    ["cursor", cursor],
28
  ]) {
29
    if (v !== undefined && v !== "" && k !== undefined) {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "GET",
35
    headers: {
36
      "x-api-token": auth.apiToken,
37
    },
38
    body: undefined,
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46