//native
type Digitalocean = {
token: string;
};
/**
* Tag a Resource
* Resources can be tagged by sending a POST request to `/v2/tags/$TAG_NAME/resources` with an array of json objects containing `resource_id` and `resource_type` attributes.
Currently only tagging of Droplets, Databases, Images, Volumes, and Volume Snapshots is supported. `resource_type` is expected to be the string `droplet`, `database`, `image`, `volume` or `volume_snapshot`. `resource_id` is expected to be the ID of the resource as a string.
*/
export async function main(
auth: Digitalocean,
tag_id: string,
body: {
resources: {
resource_id?: string;
resource_type?: "droplet" | "image" | "volume" | "volume_snapshot";
}[];
},
) {
const url = new URL(
`https://api.digitalocean.com/v2/tags/${tag_id}/resources`,
);
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