0

Get conversations by customer

by
Published Oct 17, 2025

Retrieves a paginated list of conversations using the unique Customer ID. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.conversation.read|org.permission.conversation.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 conversations by customer
7
 * Retrieves a paginated list of conversations using the unique Customer ID.
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.conversation.read|org.permission.conversation.read|
14
 */
15
export async function main(
16
  auth: Kustomer,
17
  id: string,
18
  page: string | undefined,
19
  pageSize: string | undefined,
20
  fromDate: string | undefined,
21
) {
22
  const url = new URL(
23
    `https://api.kustomerapp.com/v1/customers/${id}/conversations`,
24
  );
25
  for (const [k, v] of [
26
    ["page", page],
27
    ["pageSize", pageSize],
28
    ["fromDate", fromDate],
29
  ]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "GET",
36
    headers: {
37
      Authorization: "Bearer " + auth.apiKey,
38
    },
39
    body: undefined,
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47