0

Create a domain record

by
Published Oct 17, 2025

Adds a new Domain Record to the zonefile this Domain represents.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Create a domain record
7
 * Adds a new Domain Record to the zonefile this Domain represents.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  domainId: string,
13
  body: {
14
    created?: string;
15
    id?: number;
16
    name?: string;
17
    port?: number;
18
    priority?: number;
19
    protocol?: string;
20
    service?: string;
21
    tag?: "issue" | "issuewild" | "iodef";
22
    target?: string;
23
    ttl_sec?: number;
24
    type?: "A" | "AAAA" | "NS" | "MX" | "CNAME" | "TXT" | "SRV" | "PTR" | "CAA";
25
    updated?: string;
26
    weight?: number;
27
  },
28
) {
29
  const url = new URL(
30
    `https://api.linode.com/${apiVersion}/domains/${domainId}/records`,
31
  );
32

33
  const response = await fetch(url, {
34
    method: "POST",
35
    headers: {
36
      "Content-Type": "application/json",
37
      Authorization: "Bearer " + auth.token,
38
    },
39
    body: JSON.stringify(body),
40
  });
41
  if (!response.ok) {
42
    const text = await response.text();
43
    throw new Error(`${response.status} ${text}`);
44
  }
45
  return await response.json();
46
}
47