0

Remove a Database User

by
Published Dec 20, 2024

To remove a specific database user, send a DELETE request to `/v2/databases/$DATABASE_ID/users/$USERNAME`. A status of 204 will be given. This indicates that the request was processed successfully, but that no response body is needed. Note: User management is not supported for Redis clusters.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Remove a Database User
7
 * To remove a specific database user, send a DELETE request to
8
`/v2/databases/$DATABASE_ID/users/$USERNAME`.
9

10
A status of 204 will be given. This indicates that the request was processed
11
successfully, but that no response body is needed.
12

13
Note: User management is not supported for Redis clusters.
14

15
 */
16
export async function main(
17
  auth: Digitalocean,
18
  database_cluster_uuid: string,
19
  username: string,
20
) {
21
  const url = new URL(
22
    `https://api.digitalocean.com/v2/databases/${database_cluster_uuid}/users/${username}`,
23
  );
24

25
  const response = await fetch(url, {
26
    method: "DELETE",
27
    headers: {
28
      Authorization: "Bearer " + auth.token,
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38