0

Retrieve a Droplet Action

by
Published Dec 20, 2024

To retrieve a Droplet action, send a GET request to `/v2/droplets/$DROPLET_ID/actions/$ACTION_ID`. The response will be a JSON object with a key called `action`. The value will be a Droplet action object.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Retrieve a Droplet Action
7
 * To retrieve a Droplet action, send a GET request to
8
`/v2/droplets/$DROPLET_ID/actions/$ACTION_ID`.
9

10
The response will be a JSON object with a key called `action`. The value will
11
be a Droplet action object.
12

13
 */
14
export async function main(
15
  auth: Digitalocean,
16
  droplet_id: string,
17
  action_id: string,
18
) {
19
  const url = new URL(
20
    `https://api.digitalocean.com/v2/droplets/${droplet_id}/actions/${action_id}`,
21
  );
22

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