0

Add a new organization

by
Published Oct 17, 2025

Adds a new organization.

Script pipedrive Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Pipedrive = {
3
  apiToken: string;
4
};
5
/**
6
 * Add a new organization
7
 * Adds a new organization.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  body: {
12
    name?: string;
13
    owner_id?: number;
14
    add_time?: string;
15
    update_time?: string;
16
    visible_to?: number;
17
    label_ids?: number[];
18
  },
19
) {
20
  const url = new URL(`https://api.pipedrive.com/api/v2/organizations`);
21

22
  const response = await fetch(url, {
23
    method: "POST",
24
    headers: {
25
      "Content-Type": "application/json",
26
      "x-api-token": auth.apiToken,
27
    },
28
    body: JSON.stringify(body),
29
  });
30
  if (!response.ok) {
31
    const text = await response.text();
32
    throw new Error(`${response.status} ${text}`);
33
  }
34
  return await response.json();
35
}
36