List Requests
One script reply has been approved by the moderators Verified

Allowed for

  • End Users
Created by hugo697 844 days ago Picked 1 time
Submitted by hugo697 Typescript (fetch-only)
Verified 298 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * List Requests
8
 * #### Allowed for
9

10
* End Users
11

12
 */
13
export async function main(auth: Zendesk) {
14
  const url = new URL(`https://${auth.subdomain}.zendesk.com/api/v2/requests`);
15

16
  const response = await fetch(url, {
17
    method: "GET",
18
    headers: {
19
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
20
    },
21
    body: undefined,
22
  });
23
  if (!response.ok) {
24
    const text = await response.text();
25
    throw new Error(`${response.status} ${text}`);
26
  }
27
  return await response.json();
28
}
29