To add multiple sites to Cloudflare at once and more efficiently, you can do so via the Cloudflare API.
Adding multiple sites can be useful when you:
- Have multiple domains mapping back to a single, canonical domain (common for domains in different countries - such as
.com.au
,.co.uk
- that you want protected by Cloudflare). - Are apartner ↗, agency, or IT consultancy, and manage multiple domains on behalf of your customers.
- Are moving an existing set of sites over to Cloudflare.
Using the API will allow you to add multiple sites quickly and efficiently, especially if you are already familiar with how to change your name-servers or add a DNS record.
This tutorial assumes domains will be added usingfull mode.
To add multiple sites to Cloudflare via automation, you need:
- An existingCloudflare account.
- Command line with
curl
- A CloudflareAPI token with one of the following permissions:
- Zone-level
Administrator
- Zone-level
Zone: Edit
andDNS: Edit
- Account-level
Domain Administrator
- Zone-level
- To have disabledDNSSEC for each domain at your registrar (where you bought your domain name).
- Follow thistutorial to migrate an existing DNS zone without having to disable DNSSEC
Provider-specific instructions
This is not an exhaustive list of how to update DS records in other providers, but the following links may be helpful:
If your previous provider allows you to add DNSKEY records on the zone apex and use these records in responses to DNS queries, refer to thismigration tutorial to learn how to migrate a zone with DNSSEC enabled.
- Create a list of domains you want to add, each on a separate line (newline separated), stored in a file such as
domains.txt
. - Create a bash script
add-multiple-zones.sh
and add the following. Adddomains.txt
to the same directory or update its path accordingly.
fordomainin$(catdomains.txt);doprintf"Adding${domain}:\n"curlhttps://api.cloudflare.com/client/v4/zones\--header"Authorization: Bearer <API_TOKEN>"\--header"Content-Type: application/json"\--data'{"account": {"id":"<ACCOUNT_ID>"},"name": "'"$domain"'","type": "full"}'printf"\n\n"done
- Open the command line and run:
bashadd-multiple-zones.sh
There are limitations on the number of domains you can add at a time. If you attempt to add more than 50 domains at a time, any additional domains will be blocked until your current domains are active.
After adding a domain, it will be in aPending Nameserver Update
state.
jq
↗ is a command-line tool that parses and beautifies JSON outputs.
This tool is a requirement to complete anyAdditional options
steps in this tutorial.
echo'{"foo":{"bar":"foo","testing":"hello"}}'|jq.
Refer tojq
documentation ↗ for more information.
Cloudflare offers aquick scan that helps populate a zone's DNS records. This scan is a best effort attempt based on a predefined list of commonly used record names and types.
This API call requires the domainID
. This can be found in the following locations:
Usingjq
with the first option above, modify your scriptadd-multiple-zones.sh
to extract the domain ID and run a subsequent API call to quick scan DNS records.
fordomainin$(catdomains.txt);doprintf"Adding ${domain}:\n"add_output=`curl https://api.cloudflare.com/client/v4/zones\--header "Authorization: Bearer <API_TOKEN>"\--header "Content-Type: application/json"\--data '{"account": {"id":"<ACCOUNT_ID>"},"name": "'"$domain"'","type": "full"}'`echo$add_output|jq.domain_id=`echo $add_output | jq -r .result.id`printf"\n\n"printf"DNS quick scanning ${domain}:\n"scan_output=`curl --request POST https://api.cloudflare.com/client/v4/zones/$domain_id/dns_records/scan\--header "X-Auth-Email: <EMAIL>"\--header "X-Auth-Key: <API_KEY>"`echo$scan_output|jq.done
For each domain to become active on Cloudflare, it must be activated in eitherFull setup orPartial setup. The following script will output a list containing the nameservers associated with each domain.
You can find your zones nameservers in the following locations:
- Modify your script
add-multiple-zones.sh
to print a CSV with data from theCreate Zone
JSON response.
fordomainin$(catdomains.txt);doprintf"Adding ${domain}:\n"add_output=`curl https://api.cloudflare.com/client/v4/zones\--header "Authorization: Bearer <API_TOKEN>"\--header "Content-Type: application/json"\--data '{"account": {"id": "<ACCOUNT_ID>"},"name": "'"$domain"'","type": "full"}'`#Createcsvofnameserversecho$add_output|jq-r'[.result.name,.result.id,.result.name_servers[]] | @csv'>>/tmp/domain_nameservers.csvdomain_id=`echo $add_output | jq -r .result.id`printf"\n\n"printf"DNS quick scanning ${domain}:\n"scan_output=`curl --request POST https://api.cloudflare.com/client/v4/zones/$domain_id/dns_records/scan\--header "X-Auth-Email: <EMAIL>"\--header "X-Auth-Key: <API_KEY>"`echo$scan_output|jq.doneprintf"name_servers are saved in /tmp/domain_nameservers"cat/tmp/domain_nameservers.csv
ID | ZONE | NAME SERVERS |
---|---|---|
<ZONE_ID> | example.com | arya.ns.cloudflare.com ,tim.ns.cloudflare.com |
- Use the values in theNAME SERVERS column toupdate the nameservers at the registrar of each domain.
There are limitations on the number of domains you can add at a time. If you attempt to add more than 50 domains at a time, any additional domains will be blocked until your current domains are active.
After that, you cannot have more pending sites than active sites associated with your Cloudflare account. We recommend waiting until your pending sites have beenactivated before adding additional domains.
If any errors were returned in this process, the domain may not be registered (or only just registered), be a subdomain, or otherwise been invalid. For more details, refer toCannot add domain.
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark