0

List Sessions

by
Published Nov 7, 2023

If authenticated as an admin, returns all the account's sessions. If authenticated as an agent or end user, returns only the sessions of the user making the request. #### Pagination - Cursor pagination (recommended) - Offset pagination See Pagination. #### Allowed For * Admins, Agents, End users

Script zendesk Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 399 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * List Sessions
8
 * If authenticated as an admin, returns all the account's sessions. If authenticated as an agent or end user, returns only the sessions of the user making the request.
9

10
#### Pagination
11

12
- Cursor pagination (recommended)
13
- Offset pagination
14

15
See Pagination.
16

17
#### Allowed For
18

19
* Admins, Agents, End users
20

21
 */
22
export async function main(auth: Zendesk) {
23
  const url = new URL(`https://${auth.subdomain}.zendesk.com/api/v2/sessions`);
24

25
  const response = await fetch(url, {
26
    method: "GET",
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.json();
37
}
38