0

Add a new deal

by
Published Oct 17, 2025

Adds a new deal.

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 deal
7
 * Adds a new deal.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  body: {
12
    title: string;
13
    owner_id?: number;
14
    person_id?: number;
15
    org_id?: number;
16
    pipeline_id?: number;
17
    stage_id?: number;
18
    value?: number;
19
    currency?: string;
20
    add_time?: string;
21
    update_time?: string;
22
    stage_change_time?: string;
23
    is_deleted?: false | true;
24
    status?: string;
25
    probability?: number;
26
    lost_reason?: string;
27
    visible_to?: number;
28
    close_time?: string;
29
    won_time?: string;
30
    lost_time?: string;
31
    expected_close_date?: string;
32
    label_ids?: number[];
33
  },
34
) {
35
  const url = new URL(`https://api.pipedrive.com/api/v2/deals`);
36

37
  const response = await fetch(url, {
38
    method: "POST",
39
    headers: {
40
      "Content-Type": "application/json",
41
      "x-api-token": auth.apiToken,
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51