0

Get all organizations

by
Published Oct 17, 2025

Returns data about all organizations.

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