//native
type Digitalocean = {
token: string;
};
/**
* Create Snapshot from a Volume
* To create a snapshot from a volume, sent a POST request to `/v2/volumes/$VOLUME_ID/snapshots`.
*/
export async function main(
auth: Digitalocean,
volume_id: string,
body: { name: string; tags?: string[] },
) {
const url = new URL(
`https://api.digitalocean.com/v2/volumes/${volume_id}/snapshots`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago