0

Get messages

by
Published Oct 17, 2025

Retrieves [messages](https://help.kustomer.com/message-options-H1tSk3QOI) for your Kustomer organization. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.message.read|org.permission.message.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 messages
7
 * Retrieves [messages](https://help.kustomer.com/message-options-H1tSk3QOI) for your Kustomer organization.
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.message.read|org.permission.message.read|
14
 */
15
export async function main(
16
  auth: Kustomer,
17
  page: string | undefined,
18
  pageSize: string | undefined,
19
  include: string | undefined,
20
  sort: string | undefined,
21
) {
22
  const url = new URL(`https://api.kustomerapp.com/v1/messages`);
23
  for (const [k, v] of [
24
    ["page", page],
25
    ["pageSize", pageSize],
26
    ["include", include],
27
    ["sort", sort],
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