0

Get Klasses

by
Published Oct 17, 2025

Retrieves all [Klasses](https://help.kustomer.com/define-attributes-Skr924HI#Attributes). ## Filter by `status` You can filter results based on the `status` of the Klass. Valid values are `enabled`, `existing_only`, and `disabled`. The default value is `enabled`. 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 Klasses
7
 * Retrieves all [Klasses](https://help.kustomer.com/define-attributes-Skr924HI#Attributes).
8

9
## Filter by `status`
10

11
You can filter results based on the `status` of the Klass. Valid values are `enabled`, `existing_only`, and `disabled`. The default value is `enabled`.
12

13
Any one of the following roles is required for this endpoint:
14

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