Netlify API is not fetching all DNS records of site

I am using the Netlify API Javascript client to get the DNS configuration of my site. My site uses Netlify managed DNS and there are 5 records in the DNS dashboard. When I make the API call using client.getDNSForSite({ site_id }) only 2 DNS records are returned in the result.

Is this a bug in Netlify, or am I doing something wrong?

1 Like

Which site is it that your api call refers to? Seems likely that you only have 2 hostnames set on it :slight_smile:

The call you are making is to fetch site settings, which probably doesn’t have a 1:1 mapping with the DNS Zone you mention seeing in our UI. If you want to make the call that shows your DNS records, try finding the call we use. It may not be directly supported in the client you’re using right now since we don’t necessarily support all possible calls there, and so you may have to make it directly (which is fine with us, may be harder for you, but not against the rules :)), after you find it using this methodology:

I checked and the Netlify dashboard invokes a different API call which isn’t in client like you mentioned. Thanks for pointing it out. Cheers!

So is this API supported? Are there plans to document it?

Heya, welcome to the forum. Can you be more specific about what API calls you’re asking about? The post linked above includes a bunch of docs about our public API, as well as instructions for how to query the same endpoints that we do in our UI.

I am talking about the API to fetch or update RRs. The current ones miss many of the records and I don’t want to rely on something in production which isn’t supported.

I’m guessing the endpoint that OP found was /dns_zones?account_slug=SLUG, which, you’re right, is not documented so we can’t say with confidence that it won’t change… though the fact that it’s not documented also doesn’t mean that it’ll just change any second. I wish I had something more concrete for you. Getting it documented may be as simple as submitting a PR here (I see there’s an issue there for another endpoint)- I would give that a shot if it’s critical for your app:

Maybe it helps someone as I had the same issue using the JS SDK.
For me this is working:

const dnsZone = await client.getDNSForSite({
  site_id: "YOUR SITE ID",
});
const dnsRecords = await client.getDnsRecords({zone_id: dnsZone[0].id})

I found it by beautifying the swagger JSON in node_modules/netlify/dist/main.js, then searching for dns_records as that’s the endpoint the UI is calling :wink:

Hi, @CanRau, thank you for sharing that solution. I sure someone will find it useful and, as a member of our support team, I definitely appreciate you taking the time to post this helpful information. Thanks again! :+1: