logo
Getting started

DNS Operations

Individual record operations, batch deletes, and domain parking

This guide covers DNS operations beyond the full-flow example. DNS record writes require domain ownership or authorized organization DNS access; parking operations require ownership. The client handles the configured API_KEY or EIP712 authentication mode.

Quick start with curl

You can manage DNS records with just curl and an API key — no SDK installation required:

# List existing records (no auth needed)
curl "https://api.namefi.io/v4/dns/records?zoneName=example.com"

# Create a CNAME record
curl -X POST "https://api.namefi.io/v4/dns/records" \
  -H "x-api-key: $NAMEFI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"zoneName":"example.com","type":"CNAME","name":"www","rdata":"cname.vercel-dns.com.","ttl":300}'

# Create a TXT record
curl -X POST "https://api.namefi.io/v4/dns/records" \
  -H "x-api-key: $NAMEFI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"zoneName":"example.com","type":"TXT","name":"_verify","rdata":"some-verification-token","ttl":300}'

This is the recommended approach for AI agents and scripts that need simple DNS management.

Read records

Fetch all DNS records for a zone:

import { createNamefiClient } from '@namefi/api-client';

const client = createNamefiClient({
  authentication: {
    apiKey: process.env.NAMEFI_API_KEY!,
    type: 'API_KEY',
  },
  logger: true,
});

const records = await client.dnsRecords.getRecords({
  zoneName: 'example.com',
});

for (const r of records) {
  console.log(`${r.name} ${r.type} ${r.rdata} (TTL: ${r.ttl}, ID: ${r.id})`);
}

Create a single record

await client.dnsRecords.createDnsRecord({
  zoneName: 'example.com',
  type: 'A',
  name: '@',
  rdata: '203.0.113.10',
  ttl: 300,
});

Update a single record

Update an existing record by its ID. Fetch records first to get the ID:

const records = await client.dnsRecords.getRecords({
  zoneName: 'example.com',
});

const apex = records.find((r) => r.name === '@' && r.type === 'A');

if (apex) {
  await client.dnsRecords.updateRecord({
    id: apex.id,
    zoneName: 'example.com',
    rdata: '198.51.100.42',
    ttl: 600,
  });
}

Delete a single record

await client.dnsRecords.deleteRecord({
  id: apex.id,
  zoneName: 'example.com',
});

Batch delete records

Delete multiple records at once by their IDs:

const records = await client.dnsRecords.getRecords({
  zoneName: 'example.com',
});

const txtRecords = records.filter((r) => r.type === 'TXT');

if (txtRecords.length > 0) {
  await client.dnsRecords.deleteRecords({
    zoneName: 'example.com',
    recordsIds: txtRecords.map((r) => r.id),
  });
}

Domain parking

Park a domain to serve a default landing page. This replaces DNS records with parking records:

// Park a domain
await client.dnsRecords.parkDomain({
  normalizedDomainName: 'example.com',
  overrideExistingRecords: true,
});

// Check if a domain is parked
const { parked } = await client.dnsRecords.isDomainParked({
  normalizedDomainName: 'example.com',
});

console.log('Parked:', parked);

Toggle parking

Enable or disable parking without removing existing records:

// Disable parking, keep existing records
await client.dnsRecords.toggleDomainParking({
  normalizedDomainName: 'example.com',
  enableParking: false,
  overrideExistingRecords: false,
});

// Re-enable parking
await client.dnsRecords.toggleDomainParking({
  normalizedDomainName: 'example.com',
  enableParking: true,
  overrideExistingRecords: false,
});

Supported record types

The API supports standard DNS record types including:

A, AAAA, CNAME, MX, TXT, NS, SRV, CAA, SOA

Record types also have zone-level restrictions. In particular, apex SOA and NS records are provider-managed and cannot be supplied as user records.

Notes

  • API_KEY requests send the x-api-key header without wallet signing. With EIP712 authentication, the SDK signs the endpoint's typed request envelope.
  • updateRecord and updateRecords require the record id — use getRecords first.
  • overrideExistingRecords on parking operations controls whether current records are replaced or preserved.
  • All batch operations are scoped to a single zoneName per request.

Troubleshooting

UNAUTHORIZED (401) on write operations

  • Missing, expired or revoked key: Check the x-api-key header and manage credentials in API Keys.
  • Wrong environment: Ensure the credential and endpoint belong to the same environment. The public production endpoint is https://api.namefi.io/v4/.

FORBIDDEN (403) on write operations

  • Check the authenticated account's domain ownership in My Domains. Organization record writes additionally depend on the account's DNS permission and supplied organization context. Frozen accounts or domains can also block writes.

SDK alternative: direct HTTP

If you encounter issues with the @namefi/api-client SDK, you can always fall back to direct HTTP with curl or any HTTP client. Pass your API key as the x-api-key header. See the curl quick start above.

On this page