0

Create Product

by
Published Oct 17, 2025
Script holded Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Holded = {
3
  apiKey: string;
4
};
5
/**
6
 * Create Product
7
 *
8
 */
9
export async function main(
10
  auth: Holded,
11
  body: {
12
    kind?: string;
13
    name?: string;
14
    desc?: string;
15
    price?: number;
16
    tax?: number;
17
    cost?: number;
18
    calculatecost?: number;
19
    purchasePrice?: number;
20
    tags?: string[];
21
    barcode?: string;
22
    sku?: string;
23
    weight?: number;
24
    stock?: number;
25
  },
26
) {
27
  const url = new URL(`https://api.holded.com/api/invoicing/v1/products`);
28

29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      key: auth.apiKey,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43