0

Add a new person

by
Published Oct 17, 2025

Adds a new person.

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 person
7
 * Adds a new person.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  body: {
12
    name?: string;
13
    owner_id?: number;
14
    org_id?: number;
15
    add_time?: string;
16
    update_time?: string;
17
    emails?: { value?: string; primary?: false | true; label?: false | true }[];
18
    phones?: { value?: string; primary?: false | true; label?: false | true }[];
19
    visible_to?: number;
20
    label_ids?: number[];
21
  },
22
) {
23
  const url = new URL(`https://api.pipedrive.com/api/v2/persons`);
24

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