0

Create customer KObject (custom Object)

by
Published Oct 17, 2025

Creates a new [KObject (custom object)](https://help.kustomer.com/define-attributes-Skr924HI) and links the KObject to a customer based on the unique customer ID. 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
 * Create customer KObject (custom Object)
7
 * Creates a new [KObject (custom object)](https://help.kustomer.com/define-attributes-Skr924HI) and links the KObject to a customer based on the unique customer ID.
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
  id: string,
19
  name: string,
20
  body: {
21
    customer?: string;
22
    company?: string;
23
    externalId?: string;
24
    title: string;
25
    description?: string;
26
    images?: string[];
27
    icon?: string;
28
    data?: {};
29
    custom?: {};
30
    tags?: string[];
31
    createdAt?: string;
32
    importedAt?: string;
33
  },
34
) {
35
  const url = new URL(
36
    `https://api.kustomerapp.com/v1/customers/${id}/klasses/${name}`,
37
  );
38

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