Reorder Group SLA Policies

#### Allowed For * Admins

Script zendesk Verified

by hugo697 ยท 11/7/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 377 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * Reorder Group SLA Policies
8
 * #### Allowed For
9

10
* Admins
11

12
 */
13
export async function main(
14
  auth: Zendesk,
15
  group_sla_policy_ids: string | undefined
16
) {
17
  const url = new URL(
18
    `https://${auth.subdomain}.zendesk.com/api/v2/group_slas/policies/reorder`
19
  );
20
  for (const [k, v] of [["group_sla_policy_ids", group_sla_policy_ids]]) {
21
    if (v !== undefined && v !== "") {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "PUT",
27
    headers: {
28
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.text();
37
}
38