0

Add a new activity

by
Published Oct 17, 2025

Adds a new activity.

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 activity
7
 * Adds a new activity.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  body: {
12
    subject?: string;
13
    type?: string;
14
    owner_id?: number;
15
    deal_id?: number;
16
    lead_id?: string;
17
    person_id?: number;
18
    org_id?: number;
19
    project_id?: number;
20
    due_date?: string;
21
    due_time?: string;
22
    duration?: string;
23
    busy?: false | true;
24
    done?: false | true;
25
    location?: {
26
      value?: string;
27
      country?: string;
28
      admin_area_level_1?: string;
29
      admin_area_level_2?: string;
30
      locality?: string;
31
      sublocality?: string;
32
      route?: string;
33
      street_number?: string;
34
      postal_code?: string;
35
    };
36
    participants?: { person_id?: number; primary?: false | true }[];
37
    attendees?: {
38
      email?: string;
39
      name?: string;
40
      status?: string;
41
      is_organizer?: false | true;
42
      person_id?: number;
43
      user_id?: number;
44
    }[];
45
    public_description?: string;
46
    priority?: number;
47
    note?: string;
48
  },
49
) {
50
  const url = new URL(`https://api.pipedrive.com/api/v2/activities`);
51

52
  const response = await fetch(url, {
53
    method: "POST",
54
    headers: {
55
      "Content-Type": "application/json",
56
      "x-api-token": auth.apiToken,
57
    },
58
    body: JSON.stringify(body),
59
  });
60
  if (!response.ok) {
61
    const text = await response.text();
62
    throw new Error(`${response.status} ${text}`);
63
  }
64
  return await response.json();
65
}
66