0

Get all events by customer for session

by
Published Oct 17, 2025

Retrieves all tracking events for a specific customer session based on the unique IDs of the customer and the session. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.event.read|org.permission.event.read|

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Get all events by customer for session
7
 * Retrieves all tracking events for a specific customer session based on the unique IDs of the customer and the session.
8

9
Any one of the following roles is required for this endpoint:
10

11
|Legacy Role|Equivalent Permission Set Role|
12
|-----|--------|
13
|org.user.event.read|org.permission.event.read|
14
 */
15
export async function main(
16
  auth: Kustomer,
17
  customerId: string,
18
  sessionId: string,
19
  page: string | undefined,
20
  pageSize: string | undefined,
21
) {
22
  const url = new URL(
23
    `https://api.kustomerapp.com/v1/customers/${customerId}/sessions/${sessionId}/events`,
24
  );
25
  for (const [k, v] of [
26
    ["page", page],
27
    ["pageSize", pageSize],
28
  ]) {
29
    if (v !== undefined && v !== "" && k !== undefined) {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "GET",
35
    headers: {
36
      Authorization: "Bearer " + auth.apiKey,
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