Search Tags

Returns an array of registered and recent tag names that start with the characters specified in the `name` query parameter. You must specify at least 2 characters. #### Pagination * Offset pagination only See Using Offset Pagination. #### Allowed For * Agents

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
 * Search Tags
8
 * Returns an array of registered and recent tag names that start with the characters specified in the `name` query parameter. You must specify at least 2 characters.
9

10
#### Pagination
11

12
* Offset pagination only
13

14
See Using Offset Pagination.
15

16

17
#### Allowed For
18

19
* Agents
20

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