0

Enumerate all active channels of the application

by
Published Oct 17, 2025

Enumerate all active channels of the application

Script ably Verified

The script

Submitted by hugo697 Bun
Verified 240 days ago
1
//native
2
type Ably = {
3
  apiKey: string;
4
};
5
/**
6
 * Enumerate all active channels of the application
7
 * Enumerate all active channels of the application
8
 */
9
export async function main(
10
  auth: Ably,
11
  format: "json" | "jsonp" | "msgpack" | "html" | undefined,
12
  limit: string | undefined,
13
  prefix: string | undefined,
14
  by: "value" | "id" | undefined,
15
  X_Ably_Version: string,
16
) {
17
  const url = new URL(`https://rest.ably.io/channels`);
18
  for (const [k, v] of [
19
    ["format", format],
20
    ["limit", limit],
21
    ["prefix", prefix],
22
    ["by", by],
23
  ]) {
24
    if (v !== undefined && v !== "" && k !== undefined) {
25
      url.searchParams.append(k, v);
26
    }
27
  }
28
  const response = await fetch(url, {
29
    method: "GET",
30
    headers: {
31
      "X-Ably-Version": X_Ably_Version,
32
      Authorization: "Bearer " + auth.apiKey,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42