0

Get KObjects (custom objects)

by
Published Oct 17, 2025

Retrieves a KObject (custom object) based on the Klass name. To learn more, see [Data Model Overview](https://support.kustomer.com/data-model-overview-SyIS1S3zM). Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.klass.read|org.permission.klass.read| |org.admin.klass.read||

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Get KObjects (custom objects)
7
 * Retrieves a KObject (custom object) based on the Klass name.
8

9
To learn more, see [Data Model Overview](https://support.kustomer.com/data-model-overview-SyIS1S3zM).
10

11
Any one of the following roles is required for this endpoint:
12

13
|Legacy Role|Equivalent Permission Set Role|
14
|-----|--------|
15
|org.user.klass.read|org.permission.klass.read|
16
|org.admin.klass.read||
17
 */
18
export async function main(
19
  auth: Kustomer,
20
  name: string,
21
  fromDate: string | undefined,
22
) {
23
  const url = new URL(`https://api.kustomerapp.com/v1/klasses/${name}`);
24
  for (const [k, v] of [["fromDate", fromDate]]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.apiKey,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42