Cloudflare API: Safer DNS Changes for Launches and Migrations

Illustrated infographic summarizing: Cloudflare API: Safer DNS Automation for Launches and Migrations

By Greg Nowak. Updated November 15, 2026.

A website migration can look finished while the most consequential decision is still waiting: where should the domain send visitors? DNS changes can affect the website, email, and whether traffic passes through Cloudflare.

The Cloudflare API makes those changes easier to inspect and repeat. For business owners, operations leads, and agencies, the useful deliverable is a launch plan someone else can understand: what changes, who approves it, how success is checked, and when to roll back.

Choose the workflow that fits the change

A single dashboard edit can be perfectly reasonable. Automation becomes useful when several records must change together, client setups repeat, or another person needs to review the proposed changes.

Situation Practical approach Essential check
One correction Dashboard edit Confirm the existing value and affected service
Website migration API read, review, update Approve the origin, proxy status, and rollback
Repeated agency setup Versioned script with client configuration Confirm the zone and credential scope
Bulk changes Reviewed import or batch request Export first and check conflicts
Choose the smallest workflow that makes the change reviewable and recoverable.

This workflow covers records in an existing Cloudflare zone. A nameserver or DNSSEC migration needs its own plan.

Set ownership and limit access

Name the approver, operator, and person checking the service. Agree a change window and a rollback trigger, such as checkout failing after the switch.

Use a scoped API token instead of a Global API key. Give inventory jobs DNS Read and change jobs DNS Write, restricted to the relevant zone. Store credentials securely and keep shell tracing disabled.

For ongoing integrations, account API tokens support DNS and avoid tying automation to one employee. Creating them requires API Token Provisioning capabilities or Super Administrator status; granted permissions must stay within the creator’s access.

These Bash examples assume curl is installed. Load the token securely and configure the target explicitly:

: "${CLOUDFLARE_API_TOKEN:?load from your secret store}"
: "${ZONE_ID:?set the target zone ID}"
: "${DNS_NAME:?set the fully qualified record name}"
CF_API='https://api.cloudflare.com/client/v4'

Save the starting state and write the reverse change

Take a dated export using Cloudflare’s import and export workflow:

curl --fail-with-body --silent --show-error \
  "$CF_API/zones/$ZONE_ID/dns_records/export" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --output "zone-before-$(date -u +%Y%m%dT%H%M%SZ).txt"

Confirm the request succeeded and inspect the file. Also retain the API response for each record being changed, including its ID and settings.

Write down which values to restore and which newly created records to remove. Reimporting an old zone file should not be assumed to undo every change. Keep the previous hosting available through the agreed verification period, and decide who can authorise rollback.

Find the exact record before updating it

Use the record-list API’s exact filters. Its general search parameter is intended for people and has unspecified matching behaviour.

curl --fail-with-body --silent --show-error --get \
  "$CF_API/zones/$ZONE_ID/dns_records" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --data-urlencode "type=A" \
  --data-urlencode "name.exact=$DNS_NAME" \
  --data-urlencode "match=all"

Check success, errors, and result_info.total_count, including pagination where needed. Zero matches means investigate before creating anything; check other record types too. Multiple matches can be intentional, so never silently select the first.

Show the current and proposed name, type, content, TTL, and proxy status for approval. Read again immediately before writing and stop if the starting state has changed. This check is not a lock: coordinate other DNS work during the window.

Apply only the approved update

This PATCH request changes an existing A record. Replace the documentation address with the approved origin IP, and set the record ID from the inspected response.

: "${DNS_RECORD_ID:?set the reviewed record ID}"
curl --fail-with-body --silent --show-error \
  "$CF_API/zones/$ZONE_ID/dns_records/$DNS_RECORD_ID" \
  --request PATCH \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"content":"198.51.100.4","ttl":1,"proxied":true}'

Here, ttl: 1 means automatic TTL, and proxied: true enables Cloudflare proxying. Include those fields only when they match the approved plan; omit them to preserve existing settings. PATCH leaves unspecified fields unchanged. A/AAAA records cannot coexist with a CNAME at the same name.

Skip writes when the desired state already exists. If a request times out, read back the record before retrying.

Treat bulk operations as a separate decision

For a reviewed zone-file import:

curl --fail-with-body --silent --show-error \
  "$CF_API/zones/$ZONE_ID/dns_records/import" \
  --request POST \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --form "[email protected]"

Cloudflare documents a 256 KiB import limit and three import requests per minute per user. Domain-name targets such as MX and CNAME content need trailing periods. Preserve intentional cf-proxied:true and cf-proxied:false tags: they override the general import proxy setting. Supported directives include $ORIGIN, $TTL, and $GENERATE; $INCLUDE is unsupported.

The batch endpoint applies operations in one database transaction and applies none if an individual action fails. Distribution across Cloudflare’s network is not atomic, so a successful batch still needs live checks.

Close the launch with evidence and a handover

  1. Read back the changed records through the API.
  2. Check public DNS, including A and AAAA where relevant.
  3. Test HTTPS, redirects, and critical journeys such as forms or checkout.
  4. Record the outcome, remaining monitoring, and rollback owner. Revoke temporary write tokens.
dig @1.1.1.1 "$DNS_NAME" A +short
dig @1.1.1.1 "$DNS_NAME" AAAA +short

A public resolver check is one observation. For proxied records, answers identify Cloudflare’s edge; use an application response or origin logs to confirm which server handled the request.

If your launch crosses several suppliers or teams, Greg can help coordinate the migration, bringing the change plan, responsibilities, verification, and handover into one practical process.

Related on GrN.dk

Need help with this kind of work?

Plan your DNS migration with Greg Get in touch with Greg.

Sources

Latest articles

See how SharePoint access changes reach internal AI search, and test how long revoked content can still appear in results, generated answers, and citations.

At month-end, reconcile Shopify Payments against your bank statement and e-conomic. Use the payout ID to trace fees, refunds, and payouts that reach your bank the following month.

Trace an intermittent NGINX 502 through Cloudflare, upstream attempts, and application logs so you can see where the request failed and who should pick it up.

Find the apps, scripts and printers that still send mail through Microsoft 365 with a mailbox password, then test a replacement before the December 2026 change.

Find subscriptions and insurance expenses in e-conomic that should be spread over several months. See how AI reads the supporting documents and how your finance lead approves the proposed allocations.

Before relying on an AI project briefing, check which files it covered. A practical workflow for tracking documents, recording gaps and verifying key claims.

Check whether your contact form rejects missing or invalid Turnstile tokens, handles failed checks for genuine users and delivers accepted enquiries to your team.

Compare Bing citations, identifiable AI visits and verified enquiries to see which pages deserve attention before you increase your AI search marketing budget.

Teamtailor is phasing out Riminder on 21 November 2026. Check your parser settings, contact fields and integrations, and make sure you have a process for deleting applicant data.

WordPress jobs running late? Learn how to separate scheduling problems, task errors and a growing backlog, then choose the right scheduler or runner.