//native
type Digitalocean = {
token: string;
};
/**
* Create a New Domain
* To create a new domain, send a POST request to `/v2/domains`. Set the "name"
attribute to the domain name you are adding. Optionally, you may set the
"ip_address" attribute, and an A record will be automatically created pointing
to the apex domain.
*/
export async function main(
auth: Digitalocean,
body: {
name?: string;
ip_address?: string;
ttl?: number;
zone_file?: string;
},
) {
const url = new URL(`https://api.digitalocean.com/v2/domains`);
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