Skip to main content
The DNS Records resource provides methods to manage DNS records for zones, including creating, updating, listing, and deleting records.

Main methods

create

Create a new DNS record for a zone.
const record = await client.dns.records.create({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
  type: 'A',
  name: 'example.com',
  content: '192.0.2.1',
  ttl: 3600,
  proxied: true
});
zone_id
string
required
Zone identifier
type
string
required
DNS record type (e.g., ‘A’, ‘AAAA’, ‘CNAME’, ‘MX’, ‘TXT’, ‘SRV’, etc.)
name
string
required
DNS record name (e.g., ‘example.com’ or ‘subdomain.example.com’)
content
string
DNS record content (varies by record type)
ttl
number
Time to live, in seconds. Use 1 for automatic (defaults to auto)
proxied
boolean
Whether the record is receiving Cloudflare’s performance and security benefits (only applicable to A, AAAA, and CNAME records)
priority
number
Record priority (required for MX and SRV records)
id
string
DNS record identifier
type
string
Record type
name
string
DNS record name
content
string
DNS record content
proxied
boolean
Whether the record is proxied through Cloudflare
ttl
number
Time to live in seconds
locked
boolean
Whether the record is locked from editing
created_on
string
When the record was created
modified_on
string
When the record was last modified

update

Overwrite an existing DNS record.
const record = await client.dns.records.update(
  '372e67954025e0ba6aaa6d586b9e0b59',
  {
    zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
    type: 'A',
    name: 'example.com',
    content: '192.0.2.2',
    ttl: 3600
  }
);
dns_record_id
string
required
DNS record identifier (first parameter)
zone_id
string
required
Zone identifier
type
string
required
DNS record type
name
string
required
DNS record name
content
string
DNS record content
ttl
number
Time to live in seconds

list

List, search, sort, and filter a zone’s DNS records.
// List all records
for await (const record of client.dns.records.list({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353'
})) {
  console.log(`${record.name} -> ${record.content}`);
}

// Filter by type
for await (const record of client.dns.records.list({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
  type: 'A'
})) {
  console.log(record);
}
zone_id
string
required
Zone identifier
type
string
Filter by DNS record type
name
string
Filter by DNS record name
content
string
Filter by DNS record content
proxied
boolean
Filter by proxy status
order
'type' | 'name' | 'content' | 'ttl' | 'proxied'
Field to order records by
direction
'asc' | 'desc'
Direction to order records

delete

Delete a DNS record.
const result = await client.dns.records.delete(
  '372e67954025e0ba6aaa6d586b9e0b59',
  { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }
);
dns_record_id
string
required
DNS record identifier (first parameter)
zone_id
string
required
Zone identifier

get

Get DNS record details.
const record = await client.dns.records.get(
  '372e67954025e0ba6aaa6d586b9e0b59',
  { zone_id: '023e105f4ecef8ad9ca31a8372d0c353' }
);
dns_record_id
string
required
DNS record identifier (first parameter)
zone_id
string
required
Zone identifier

Additional methods

edit

Update an existing DNS record (partial update).
const record = await client.dns.records.edit(
  '372e67954025e0ba6aaa6d586b9e0b59',
  {
    zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
    proxied: false
  }
);

batch

Send a batch of DNS record API calls to be executed together.
const result = await client.dns.records.batch({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
  posts: [
    {
      type: 'A',
      name: 'example.com',
      content: '192.0.2.1'
    }
  ],
  patches: [
    {
      id: '372e67954025e0ba6aaa6d586b9e0b59',
      proxied: true
    }
  ]
});

import

Import DNS records from a BIND config file.
const result = await client.dns.records.import({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
  file: 'www.example.com. 300 IN A 127.0.0.1'
});

export

Export DNS records in BIND config format.
const bindConfig = await client.dns.records.export({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353'
});

Record types

Common DNS record types include:
  • A - Maps a domain to an IPv4 address
  • AAAA - Maps a domain to an IPv6 address
  • CNAME - Creates an alias for another domain
  • MX - Specifies mail servers for the domain
  • TXT - Stores text information
  • SRV - Defines service locations
  • NS - Delegates a subdomain to different nameservers
  • CAA - Specifies which certificate authorities can issue certificates
  • PTR - Reverse DNS lookup
  • HTTPS - HTTPS service binding
  • SVCB - Service binding

Important notes

  • A/AAAA records cannot exist on the same name as CNAME records
  • NS records cannot exist on the same name as any other record type
  • Domain names are always represented in Punycode, even if Unicode characters were used
  • Use ttl: 1 for automatic TTL (Cloudflare manages it)
  • Only A, AAAA, and CNAME records support the proxied option

Example usage

import Cloudflare from 'cloudflare';

const client = new Cloudflare({
  apiToken: process.env.CLOUDFLARE_API_TOKEN
});

const zoneId = '023e105f4ecef8ad9ca31a8372d0c353';

// Create an A record with proxy enabled
const aRecord = await client.dns.records.create({
  zone_id: zoneId,
  type: 'A',
  name: 'example.com',
  content: '192.0.2.1',
  ttl: 1, // Auto
  proxied: true
});

// Create a CNAME record
const cnameRecord = await client.dns.records.create({
  zone_id: zoneId,
  type: 'CNAME',
  name: 'www',
  content: 'example.com',
  proxied: true
});

// Create an MX record
const mxRecord = await client.dns.records.create({
  zone_id: zoneId,
  type: 'MX',
  name: 'example.com',
  content: 'mail.example.com',
  priority: 10
});

// List all A records
for await (const record of client.dns.records.list({
  zone_id: zoneId,
  type: 'A'
})) {
  console.log(`${record.name}: ${record.content} (proxied: ${record.proxied})`);
}

// Update a record to disable proxy
await client.dns.records.edit(aRecord.id, {
  zone_id: zoneId,
  proxied: false
});

// Delete a record
await client.dns.records.delete(cnameRecord.id, {
  zone_id: zoneId
});

Build docs developers (and LLMs) love