Incremental User Export, Cursor 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, Cursor 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
  cursor: string | undefined,
21
  per_page: string | undefined
22
) {
23
  const url = new URL(
24
    `https://${auth.subdomain}.zendesk.com/api/v2/incremental/users/cursor`
25
  );
26
  for (const [k, v] of [
27
    ["start_time", start_time],
28
    ["cursor", cursor],
29
    ["per_page", per_page],
30
  ]) {
31
    if (v !== undefined && v !== "") {
32
      url.searchParams.append(k, v);
33
    }
34
  }
35
  const response = await fetch(url, {
36
    method: "GET",
37
    headers: {
38
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
39
    },
40
    body: undefined,
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48