Open Ticket in Agent's Browser

Allows you to instruct an agent's browser to open a ticket. When the message is successfully delivered to an agent's browser: ```http Status: 200 OK ``` When `agent_id` or `ticket_id` is invalid: ```http Status: 404 Not Found ``` #### 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
 * Open Ticket in Agent's Browser
8
 * Allows you to instruct an agent's browser to open a ticket.
9

10
When the message is successfully delivered to an agent's browser:
11

12
```http
13
Status: 200 OK
14
```
15

16
When `agent_id` or `ticket_id` is invalid:
17

18
```http
19
Status: 404 Not Found
20
```
21

22
#### Allowed For
23
* Agents
24
 */
25
export async function main(auth: Zendesk, agent_id: string, ticket_id: string) {
26
  const url = new URL(
27
    `https://${auth.subdomain}.zendesk.com/api/v2/channels/voice/agents/${agent_id}/tickets/${ticket_id}/display`
28
  );
29

30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.text();
42
}
43