Add multiple sites via automation

Last updated Oct 21, 2026 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 a partner ↗︎, 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 nameservers or add a DNS record.

This tutorial assumes domains will be added using a primary DNS setup (full).


Prerequisites

To add multiple sites to Cloudflare via automation, you need:

  • An existing Cloudflare account.
  • Command line with curl
  • A Cloudflare API token with one of the following permissions:
  • Zone-level Administrator
  • Zone-level Zone: Edit and DNS: Edit
  • Account-level Domain Administrator
  • To have disabled DNSSEC for each domain at your registrar (where you bought your domain name).<details><summary>

Provider-specific DNSSEC instructions</summary>

This is not an exhaustive list, but the following links may be helpful: - <a href="https://support.dnsimple.com/articles/cloudflare-ds-record/">DNSimple ↗︎</a> - <a href="https://support.domaindiscount24.com/hc/articles/4409759478161">Domaindiscount24 ↗︎</a> - <a href="https://help.dreamhost.com/hc/en-us/articles/219539467">DreamHost ↗︎</a> - <a href="https://www.dynadot.com/help/question/set-DNSSEC">Dynadot ↗︎</a> - <a href="https://support.enom.com/support/solutions/articles/201000065386">Enom ↗︎</a> - <a href="https://docs.gandi.net/en/domain_names/advanced_users/dnssec.html">Gandi ↗︎</a> - <a href="https://www.godaddy.com/help/add-a-ds-record-23865">GoDaddy ↗︎</a> - <a href="https://www.hostinger.com/support/3667267-how-to-use-dnssec-records-at-hostinger/">Hostinger ↗︎</a> - <a href="https://support.hover.com/support/solutions/articles/201000064716">Hover ↗︎</a> - <a href="https://faq.infomaniak.com/2187">Infomaniak ↗︎</a> - <a href="https://www.inmotionhosting.com/support/edu/cpanel/enable-dnssec-cloudflare/">InMotion Hosting ↗︎</a> - <a href="https://kb.inwx.com/en-us/3-nameserver/131">INWX ↗︎</a> - <a href="https://joker.com/faq/books/jokercom-faq-en/page/dnssec">Joker.com ↗︎</a> - <a href="https://www.name.com/support/articles/205439058-managing-dnssec">Name.com ↗︎</a> - <a href="https://www.namecheap.com/support/knowledgebase/article.aspx/9722/2232/managing-dnssec-for-domains-pointed-to-custom-dns/">Namecheap ↗︎</a> - <a href="https://support.nameisp.com/knowledgebase/dns">NameISP ↗︎</a> - <a href="https://www.namesilo.com/support/v2/articles/domain-manager/ds-records">Namesilo ↗︎</a> - <a href="https://help.ovhcloud.com/csm/en-dns-secure-domain-dnssec?id=kb_article_view&sysparm_article=KB0051637">OVH ↗︎</a> - <a href="https://support.squarespace.com/hc/articles/4404183898125-Nameservers-and-DNSSEC-for-Squarespace-managed-domains#toc-dnssec">Squarespace ↗︎</a> - <a href="https://registro.br/tecnologia/dnssec/?secao=tutoriais-dns">Registro.br ↗︎</a> - <a href="https://kb.porkbun.com/article/93-how-to-install-dnssec">Porkbun ↗︎</a> (do not fill out keyData) - <a href="https://www.transip.eu/knowledgebase/150-secure-domains-custom-nameservers-dnssec/">TransIP ↗︎</a></details>

Note

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 this migration tutorial to learn how to migrate a zone with DNSSEC enabled.


1. Add domains

  1. Create a list of domains you want to add, each on a separate line (newline separated), stored in a file such as domains.txt.
  2. Create a bash script add-multiple-zones.sh and add the following. Add domains.txt to the same directory or update its path accordingly.
  for domain in $(cat domains.txt); do
    printf "Adding ${domain}:\n"

    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"
    }'

    printf "\n\n"
  done
  1. Open the command line and run:
bash add-multiple-zones.sh

Caution

There are limitations on the number of domains you can add at a time. Refer to limitations for details.

After adding a domain, it will be in a Pending Nameserver Update state.

Additional options

jq

jq ↗︎ is a command-line tool that parses and beautifies JSON outputs.

This tool is a requirement to complete any additional option steps in this tutorial.

echo '{"foo":{"bar":"foo","testing":"hello"}}' | jq .

Refer to jq documentation ↗︎ for more information.

Quick scan

Cloudflare offers a quick 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 domain ID. This can be found in the following locations:

Using jq with the first option above, modify your script add-multiple-zones.sh to extract the domain ID and run a subsequent API call to quick scan DNS records.

  for domain in $(cat domains.txt); do
    printf "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

2. Update nameservers

For each domain to become active on Cloudflare, it must be activated in either Full setup or Partial 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:

  • Create Zone
  • Zone Details

  • Modify your script add-multiple-zones.sh to print a CSV with data from the Create Zone JSON response.

  for domain in $(cat domains.txt); do
    printf "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"
      }'`

    # Create csv of nameservers
    echo $add_output | jq -r '[.result.name,.result.id,.result.name_servers[]] | @csv' >> /tmp/domain_nameservers.csv

    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

  printf "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
  1. Use the values in the NAME SERVERS column to update the nameservers at the registrar of each domain.

Limitations

There are limitations on the number of domains you can add at a time - specifically, you can only sign up a maximum of 25 domains every 10 minutes.

In addition, if you have over 50 domains and, of those domains, more are pending than active, you will be blocked from adding more. We recommend waiting until your pending sites have been activated before adding more.

Common issues

If any errors were returned in this process, the domain may not be registered (or only just registered), be a subdomain, or be otherwise invalid. For more details, refer to Cannot add domain.

Was this helpful?

YesNo

On this page

Add multiple sites via automation - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/fundamentals/manage-domains/add-multiple-sites-automation/#page","headline":"Add multiple sites via automation","description":"To add multiple sites to Cloudflare at once and more efficiently, you can do so via the Cloudflare API.","url":"https://developers.cloudflare.com/fundamentals/manage-domains/add-multiple-sites-automation/","inLanguage":"en","image":"https://developers.cloudflare.com/fundamentals/manage-domains/add-multiple-sites-automation/og.png?v=ab586b664ff8e083","dateModified":"2026-10-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Learn how to onboard your domain to Cloudflare, to speed up and protect your website or application. title: Onboard a domain image: https://developers.cloudflare.com/fundamentals/manage-domains/add-site/og.png?v=8cee46df3198c452


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/fundamentals/llms.txt
Use this file to discover all available pages before exploring further.