0

Bulk create KObjects (custom objects)

by
Published Oct 17, 2025

Creates KObjects (custom objects) in bulk. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.kobject.write|org.permission.kobject.create| ||org.permission.kobject.kobject_*.create|

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Bulk create KObjects (custom objects)
7
 * Creates KObjects (custom objects) in bulk.
8

9
Any one of the following roles is required for this endpoint:
10

11
|Legacy Role|Equivalent Permission Set Role|
12
|-----|--------|
13
|org.user.kobject.write|org.permission.kobject.create|
14
||org.permission.kobject.kobject_*.create|
15
 */
16
export async function main(
17
  auth: Kustomer,
18
  name: string,
19
  body: {
20
    customer?: string;
21
    company?: string;
22
    externalId?: string;
23
    title: string;
24
    description?: string;
25
    images?: string[];
26
    icon?: string;
27
    data?: {};
28
    custom?: {};
29
    tags?: string[];
30
    createdAt?: string;
31
    importedAt?: string;
32
  }[],
33
) {
34
  const url = new URL(`https://api.kustomerapp.com/v1/klasses/${name}/bulk`);
35

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