List Ticket Forms

Returns a list of all ticket forms for your account if accessed as an admin or agent. End users only see ticket forms that have `end_user_visible` set to true. #### Allowed For * Anyone

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
 * List Ticket Forms
8
 * Returns a list of all ticket forms for your account if accessed as an admin or agent. End users only see ticket forms that have `end_user_visible` set to true.
9

10
#### Allowed For
11

12
* Anyone
13

14
 */
15
export async function main(
16
  auth: Zendesk,
17
  active: string | undefined,
18
  end_user_visible: string | undefined,
19
  fallback_to_default: string | undefined,
20
  associated_to_brand: string | undefined
21
) {
22
  const url = new URL(
23
    `https://${auth.subdomain}.zendesk.com/api/v2/ticket_forms`
24
  );
25
  for (const [k, v] of [
26
    ["active", active],
27
    ["end_user_visible", end_user_visible],
28
    ["fallback_to_default", fallback_to_default],
29
    ["associated_to_brand", associated_to_brand],
30
  ]) {
31
    if (v !== undefined && v !== "") {
32
      url.searchParams.append(k, v);
33
    }
34
  }
35
  const response = await fetch(url, {
36
    method: "GET",
37
    headers: {
38
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
39
    },
40
    body: undefined,
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48