0

Add a product

by
Published Oct 17, 2025

Adds a new product to the Products inventory. For more information, see the tutorial for adding a product.

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 product
7
 * Adds a new product to the Products inventory. For more information, see the tutorial for adding a product.
8
 */
9
export async function main(
10
  auth: Pipedrive,
11
  body: { name: string } & {
12
    code?: string;
13
    description?: string;
14
    unit?: string;
15
    tax?: number;
16
    category?: number;
17
    owner_id?: number;
18
    is_linkable?: false | true;
19
    visible_to?: 1 | 3 | 5 | 7;
20
    prices?: {}[];
21
  } & {
22
    billing_frequency?:
23
      | "one-time"
24
      | "annually"
25
      | "semi-annually"
26
      | "quarterly"
27
      | "monthly"
28
      | "weekly";
29
  } & { billing_frequency_cycles?: number },
30
) {
31
  const url = new URL(`https://api.pipedrive.com/api/v2/products`);
32

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