Skip to main content
The Zones resource provides methods to manage Cloudflare zones, which represent domains or subdomains on the Cloudflare platform.

Main methods

create

Create a new zone.
const zone = await client.zones.create({
  account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
  name: 'example.com',
  type: 'full'
});
account
object
required
The account the zone belongs to
account.id
string
Account identifier
name
string
required
The domain name (e.g., ‘example.com’)
type
'full' | 'partial' | 'secondary' | 'internal'
Zone type. A full zone implies DNS is hosted with Cloudflare. A partial zone is typically a partner-hosted zone or CNAME setup.
id
string
Zone identifier
name
string
The domain name
status
'initializing' | 'pending' | 'active' | 'moved'
The zone status on Cloudflare
name_servers
string[]
The name servers Cloudflare assigns to the zone
created_on
string
When the zone was created
activated_on
string | null
The last time proof of ownership was detected and the zone was made active

list

List, search, sort, and filter zones. Listing zones across more than 500 accounts is currently not allowed.
// Automatically fetches more pages as needed
for await (const zone of client.zones.list()) {
  console.log(zone.name);
}

// Filter by account
for await (const zone of client.zones.list({
  account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
  status: 'active'
})) {
  console.log(zone.name);
}
account
object
Filter by account
account.id
string
Filter by account ID
account.name
string
Filter by account name (supports operators like ‘contains’, ‘starts_with’, etc.)
name
string
Filter by domain name (supports operators like ‘contains’, ‘starts_with’, ‘ends_with’, etc.)
status
'initializing' | 'pending' | 'active' | 'moved'
Filter by zone status
order
'name' | 'status' | 'account.id' | 'account.name' | 'plan.id'
Field to order zones by
direction
'asc' | 'desc'
Direction to order zones
match
'any' | 'all'
Whether to match all search requirements or at least one

delete

Delete an existing zone.
const result = await client.zones.delete({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353'
});
zone_id
string
required
Zone identifier

edit

Edit a zone. Only one zone property can be changed at a time.
const zone = await client.zones.edit({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353',
  paused: false
});
zone_id
string
required
Zone identifier
paused
boolean
Whether the zone is only using Cloudflare DNS services (true means no security or performance benefits)
type
'full' | 'partial' | 'secondary' | 'internal'
Zone type (Enterprise only)
vanity_name_servers
string[]
Custom name servers (Business and Enterprise plans only)

get

Get zone details.
const zone = await client.zones.get({
  zone_id: '023e105f4ecef8ad9ca31a8372d0c353'
});
zone_id
string
required
Zone identifier

Zone type

interface Zone {
  id: string;
  account: {
    id?: string;
    name?: string;
  };
  name: string;
  status?: 'initializing' | 'pending' | 'active' | 'moved';
  type?: 'full' | 'partial' | 'secondary' | 'internal';
  paused?: boolean;
  development_mode: number;
  name_servers: string[];
  original_name_servers: string[] | null;
  original_registrar: string | null;
  created_on: string;
  modified_on: string;
  activated_on: string | null;
  owner: {
    id?: string;
    name?: string;
    type?: string;
  };
  meta: {
    cdn_only?: boolean;
    dns_only?: boolean;
    foundation_dns?: boolean;
    page_rule_quota?: number;
    phishing_detected?: boolean;
  };
  vanity_name_servers?: string[];
}

Sub-resources

The Zones resource provides access to several sub-resources:
  • settings - Manage zone settings (SSL, caching, security, etc.)
  • activationCheck - Trigger activation checks for the zone
  • customNameservers - Manage custom nameservers
  • holds - Manage zone holds
  • subscriptions - Manage zone subscriptions
  • plans - View available rate plans

Example usage

import Cloudflare from 'cloudflare';

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

// Create a new zone
const zone = await client.zones.create({
  account: { id: '023e105f4ecef8ad9ca31a8372d0c353' },
  name: 'example.com',
  type: 'full'
});

console.log('Zone created:', zone.id);
console.log('Name servers:', zone.name_servers);

// List all active zones
for await (const zone of client.zones.list({ status: 'active' })) {
  console.log(`${zone.name} - ${zone.status}`);
}

// Get zone details
const zoneDetails = await client.zones.get({
  zone_id: zone.id
});

// Pause a zone (DNS only)
const pausedZone = await client.zones.edit({
  zone_id: zone.id,
  paused: true
});

// Update zone settings
await client.zones.settings.edit({
  zone_id: zone.id,
  items: [
    { id: 'always_use_https', value: 'on' },
    { id: 'ssl', value: 'flexible' }
  ]
});

Build docs developers (and LLMs) love