0

Incremental Sample Export

by
Published Nov 7, 2023

Use this endpoint to test the incremental export format. It's more strict in terms of rate limiting, at 10 requests per 20 minutes instead of 10 requests per minute. It also returns only up to 50 results per request. Otherwise, it's identical to the above APIs. Use the `incremental_resource` parameter to specify the resource. Possible values are "tickets", "ticket_events", "users", or "organizations".

Script zendesk Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * Incremental Sample Export
8
 * Use this endpoint to test the incremental export format. It's more strict in terms of rate limiting,
9
at 10 requests per 20 minutes instead of 10 requests per minute. It also returns only up to 50
10
results per request. Otherwise, it's identical to the above APIs.
11

12
Use the `incremental_resource` parameter to specify the resource. Possible values are "tickets", "ticket_events", "users", or "organizations".
13

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