Incremental User Export, Time Based

#### Allowed For * Admins #### Sideloading See Users sideloads.

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
 * Incremental User Export, Time Based
8
 * #### Allowed For
9

10
 * Admins
11

12
#### Sideloading
13

14
See Users sideloads.
15

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