List devices registered for receiving push notifications
One script reply has been approved by the moderators Verified

List of device details of devices registed for push notifications.

Created by hugo697 138 days ago
Submitted by hugo697 Bun
Verified 138 days ago
1
//native
2
type Ably = {
3
  apiKey: string;
4
};
5
/**
6
 * List devices registered for receiving push notifications
7
 * List of device details of devices registed for push notifications.
8
 */
9
export async function main(
10
  auth: Ably,
11
  format: "json" | "jsonp" | "msgpack" | "html" | undefined,
12
  deviceId: string | undefined,
13
  clientId: string | undefined,
14
  limit: string | undefined,
15
  X_Ably_Version: string,
16
) {
17
  const url = new URL(`https://rest.ably.io/push/deviceRegistrations`);
18
  for (const [k, v] of [
19
    ["format", format],
20
    ["deviceId", deviceId],
21
    ["clientId", clientId],
22
    ["limit", limit],
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