0

Retrieve an Existing Snapshot

by
Published Dec 20, 2024

To retrieve information about a snapshot, send a GET request to `/v2/snapshots/$SNAPSHOT_ID`. The response will be a JSON object with a key called `snapshot`. The value of this will be an snapshot object containing the standard snapshot attributes.

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 an Existing Snapshot
7
 * To retrieve information about a snapshot, send a GET request to
8
`/v2/snapshots/$SNAPSHOT_ID`.
9

10
The response will be a JSON object with a key called `snapshot`. The value of
11
this will be an snapshot object containing the standard snapshot attributes.
12

13
 */
14
export async function main(auth: Digitalocean, snapshot_id: string) {
15
  const url = new URL(
16
    `https://api.digitalocean.com/v2/snapshots/${snapshot_id}`,
17
  );
18

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