Updates a key

Update the API key with the specified key ID, for the application with the specified application ID.

Script ably Verified

by hugo697 ยท 10/17/2025

The script

Submitted by hugo697 Bun
Verified 220 days ago
1
//native
2
type Ably = {
3
  accessToken: string;
4
};
5
/**
6
 * Updates a key
7
 * Update the API key with the specified key ID, for the application with the specified application ID.
8
 */
9
export async function main(
10
  auth: Ably,
11
  app_id: string,
12
  key_id: string,
13
  body: { name?: string; capability?: {} },
14
) {
15
  const url = new URL(
16
    `https://control.ably.net/v1/apps/${app_id}/keys/${key_id}`,
17
  );
18

19
  const response = await fetch(url, {
20
    method: "PATCH",
21
    headers: {
22
      "Content-Type": "application/json",
23
      Authorization: "Bearer " + auth.accessToken,
24
    },
25
    body: JSON.stringify(body),
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33