0

Create KObject

by
Published Oct 17, 2025

Creates a new KObject (custom object).

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Create KObject
7
 * Creates a new KObject (custom object).
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  name: string,
12
  body: {
13
    customer?: string;
14
    company?: string;
15
    externalId?: string;
16
    title: string;
17
    description?: string;
18
    images?: string[];
19
    icon?: string;
20
    data?: {};
21
    custom?: {};
22
    tags?: string[];
23
    createdAt?: string;
24
    importedAt?: string;
25
  },
26
) {
27
  const url = new URL(`https://api.kustomerapp.com/v1/klasses/${name}`);
28

29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + 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