[Solved] Problems returning all domains from a zone via API

Hello everybody! I’m getting in touch for the following, I’m trying to automate the notification of the expiration of the domains of my various clients and as the majority of them use cloudflare, so as not to have to manually add domain by domain in the DNS expiration notification system, I thought about automating it via API.

In this case, I am using the following command to pull the domains from all the zones I manage:

curl -X GET https://api.cloudflare.com/client/v4/zones -H "Authorization: Bearer API_TOKEN" -H "Content-Type: application/json" > data.json

However, the generated data.json file is apparently incomplete! For example, in one of the zones I manage I have 12 domains and from that zone only 4 were returned in the list.

I don’t know if it’s some limitation, but in total, only 20 DNSs were returned in this json from 6 different zones out of 12 zones that I manage.

Does anyone know what this could be?

Do you mean pull the DNS records from the zones?

If so you need to get the list of zones, then loop through each one to read all the DNS records. I do that here…

However, you mentioned getting the domain expiry date. For that you need to use the registrar endpoints…

(Note that the registrar API endpoints require use of the global API key, no token permission exist for this. I’ll have my registrar option up in the next few days).

No, in this case I don’t want the DNS entries, my objective is the customer domains, such as:

In total, my account manages 12 different zones (mine and 11 other clients) and I must have at least 40 different domains administered, but the command above is only capturing 20.

The API command returns in pages of 20 by default (as some users on Cloudflare have >10K zones in an account, so results are paginated).

You have to request a page at a time, each page can return up to 50 zones. Make the API query with .../zones?page=1&per_page=50, see…

But as I say, the zone endpoint won’t give you any domain registration information as those zones could be registered elsewhere, or be subdomain setups, or suffixes of domains registered by another owner. You need to use the registrar endpoint.

1 Like

Thank you very much, the problem was the lack of ?page=1&per_page=50

In my case, the tool to check the validity of domains will be GitHub - ak545/dns-domain-expiration-checker: This is a python script to check the expiration dates for the registration of your domains., I’m just using Cloudflare in case a customer adds a domain to their account without notifying me. , I will already be monitoring the expiration of this DNS and I will not have headaches with it calling me in the early hours of the morning that the site or system is down.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.