0

Get SLA by ID

by
Published Oct 17, 2025

Retrieves an [SLA](https://help.kustomer.com/service-level-agreements-SyZ4xWcgf) based on the unique SLA ID. Use the optional `versions` query param to retrieve information about SLA versions. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.sla.read|org.permission.sla.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 SLA by ID
7
 * Retrieves an [SLA](https://help.kustomer.com/service-level-agreements-SyZ4xWcgf) based on the unique SLA ID.
8

9
Use the optional `versions` query param to retrieve information about SLA versions.
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.sla.read|org.permission.sla.read|
16
 */
17
export async function main(
18
  auth: Kustomer,
19
  id: string,
20
  versions: "active" | "all" | undefined,
21
) {
22
  const url = new URL(`https://api.kustomerapp.com/v1/slas/${id}`);
23
  for (const [k, v] of [["versions", versions]]) {
24
    if (v !== undefined && v !== "" && k !== undefined) {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "GET",
30
    headers: {
31
      Authorization: "Bearer " + auth.apiKey,
32
    },
33
    body: undefined,
34
  });
35
  if (!response.ok) {
36
    const text = await response.text();
37
    throw new Error(`${response.status} ${text}`);
38
  }
39
  return await response.json();
40
}
41