0

Get Events Volume from Workspace

by
Published Oct 17, 2025

Enumerates the Workspace event volumes over time in minute increments. The rate limit for this endpoint is 60 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.

Script segment Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Segment = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Get Events Volume from Workspace
8
 * Enumerates the Workspace event volumes over time in minute increments.
9

10

11
The rate limit for this endpoint is 60 requests per minute, which is lower than the default due to access pattern restrictions. Once reached, this endpoint will respond with the 429 HTTP status code with headers indicating the limit parameters. See Rate Limiting for more information.
12
 */
13
export async function main(
14
  auth: Segment,
15
  granularity: "DAY" | "HOUR" | "MINUTE" | undefined,
16
  startTime: string | undefined,
17
  endTime: string | undefined,
18
  groupBy: string | undefined,
19
  sourceId: string | undefined,
20
  eventName: string | undefined,
21
  eventType: string | undefined,
22
  appVersion: string | undefined,
23
  pagination: string | undefined,
24
) {
25
  const url = new URL(`${auth.baseUrl}/events/volume`);
26
  for (const [k, v] of [
27
    ["granularity", granularity],
28
    ["startTime", startTime],
29
    ["endTime", endTime],
30
    ["groupBy", groupBy],
31
    ["sourceId", sourceId],
32
    ["eventName", eventName],
33
    ["eventType", eventType],
34
    ["appVersion", appVersion],
35
    ["pagination", pagination],
36
  ]) {
37
    if (v !== undefined && v !== "" && k !== undefined) {
38
      url.searchParams.append(k, v);
39
    }
40
  }
41
  const response = await fetch(url, {
42
    method: "GET",
43
    headers: {
44
      Authorization: "Bearer " + auth.token,
45
    },
46
    body: undefined,
47
  });
48
  if (!response.ok) {
49
    const text = await response.text();
50
    throw new Error(`${response.status} ${text}`);
51
  }
52
  return await response.json();
53
}
54