0

List Neighbors for a Droplet

by
Published Dec 20, 2024

To retrieve a list of any "neighbors" (i.e. Droplets that are co-located on the same physical hardware) for a specific Droplet, send a GET request to `/v2/droplets/$DROPLET_ID/neighbors`. The results will be returned as a JSON object with a key of `droplets`. This will be set to an array containing objects representing any other Droplets that share the same physical hardware. An empty array indicates that the Droplet is not co-located any other Droplets associated with your account.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * List Neighbors for a Droplet
7
 * To retrieve a list of any "neighbors" (i.e. Droplets that are co-located on
8
the same physical hardware) for a specific Droplet, send a GET request to
9
`/v2/droplets/$DROPLET_ID/neighbors`.
10

11
The results will be returned as a JSON object with a key of `droplets`. This
12
will be set to an array containing objects representing any other Droplets
13
that share the same physical hardware. An empty array indicates that the
14
Droplet is not co-located any other Droplets associated with your account.
15

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

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