Export DNS Records

You can export your [BIND config](https://en.wikipedia.org/wiki/Zone_file "Zone file") through this endpoint. See [the documentation](https://developers.cloudflare.com/dns/manage-dns-records/how-to/import-and-export/ "Import and export records") for more information.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Export DNS Records
8
 * You can export your [BIND config](https://en.wikipedia.org/wiki/Zone_file "Zone file") through this endpoint.
9

10
See [the documentation](https://developers.cloudflare.com/dns/manage-dns-records/how-to/import-and-export/ "Import and export records") for more information.
11
 */
12
export async function main(auth: Cloudflare, zone_identifier: string) {
13
  const url = new URL(
14
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/dns_records/export`
15
  );
16

17
  const response = await fetch(url, {
18
    method: "GET",
19
    headers: {
20
      "X-AUTH-EMAIL": auth.email,
21
      "X-AUTH-KEY": auth.key,
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: undefined,
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.text();
31
}
32