0

Search organizations

by
Published Oct 17, 2025

Searches all organizations by name, address, notes and/or custom fields. This endpoint is a wrapper of /v1/itemSearch with a narrower OAuth scope.

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 organizations
7
 * Searches all organizations by name, address, notes and/or custom fields. This endpoint is a wrapper of /v1/itemSearch with a narrower OAuth scope.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  term: string | undefined,
12
  fields: "address" | "custom_fields" | "notes" | "name" | undefined,
13
  exact_match: string | undefined,
14
  limit: string | undefined,
15
  cursor: string | undefined,
16
) {
17
  const url = new URL(`https://api.pipedrive.com/api/v2/organizations/search`);
18
  for (const [k, v] of [
19
    ["term", term],
20
    ["fields", fields],
21
    ["exact_match", exact_match],
22
    ["limit", limit],
23
    ["cursor", cursor],
24
  ]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      "x-api-token": auth.apiToken,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42