0

Delete a Domain Record

by
Published Dec 20, 2024

To delete a record for a domain, send a DELETE request to `/v2/domains/$DOMAIN_NAME/records/$DOMAIN_RECORD_ID`. The record will be deleted and the response status will be a 204. This indicates a successful request with no body returned.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Delete a Domain Record
7
 * To delete a record for a domain, send a DELETE request to
8
`/v2/domains/$DOMAIN_NAME/records/$DOMAIN_RECORD_ID`.
9

10
The record will be deleted and the response status will be a 204. This
11
indicates a successful request with no body returned.
12

13
 */
14
export async function main(
15
  auth: Digitalocean,
16
  domain_name: string,
17
  domain_record_id: string,
18
) {
19
  const url = new URL(
20
    `https://api.digitalocean.com/v2/domains/${domain_name}/records/${domain_record_id}`,
21
  );
22

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