//native
type Digitalocean = {
token: string;
};
/**
* Create a New Reserved IP
* On creation, a reserved IP must be either assigned to a Droplet or reserved to a region.
* To create a new reserved IP assigned to a Droplet, send a POST
request to `/v2/reserved_ips` with the `droplet_id` attribute.
* To create a new reserved IP reserved to a region, send a POST request to
`/v2/reserved_ips` with the `region` attribute.
**Note**: In addition to the standard rate limiting, only 12 reserved IPs may be created per 60 seconds.
*/
export async function main(
auth: Digitalocean,
body: { droplet_id: number } | { region: string; project_id?: string },
) {
const url = new URL(`https://api.digitalocean.com/v2/reserved_ips`);
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 537 days ago