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 |
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
- Read back the changed records through the API.
- Check public DNS, including A and AAAA where relevant.
- Test HTTPS, redirects, and critical journeys such as forms or checkout.
- 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 +shortA 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
- How to Bulk Delete Cloudflare DNS Records Safely: Dashboard or API
- Your AI workflow has logs. Can they explain one bad decision?
- AI automations need a spend dashboard before the first runaway bill
Need help with this kind of work?
Plan your DNS migration with Greg Get in touch with Greg.