List all branch subdomains of site

Hi there,

Please could you advise how to list all branch subdomains of a site_id using Netlify open API?

I was hoping getSite https://open-api.netlify.com/#operation/getSite would display this under ‘domain aliases’, but I’m getting an empty array returned.

Within the Netlify dashboard I can see all of my branch subdomains.

Here’s what I’m using.

router.get('/getsite', (req, res) => {
    const site = client.getSite({
            site_id: "x",
        })
        .then(data => res.status(200).json({ message: data }))
        .catch(e => res.status(500).json({ message: 'Error', e }))
});

Many thanks!

Yup, those branch subdomains are stored separately from the site config. However, you can still access them! Have you seen this article about reverse engineering our API? If you can see it in our UI, you can API call it:

So, looking at the branch subdomains page on the domain settings page, what is shown there is the intersection of:

  1. all deployed branches (and PR’s), which you can get from the API call:

GET https://api.netlify.com/api/v1/sites/ID/deployed-branches

This will almost certainly be WAY more than is shown in our UI; that’s the AVAILABLE branch subdomains. All of them will work with the notation: branch--site.netlify.app; the only ones shown in the UI will be ones you have explicitly clicked the button (or made the API calls) to create in our UI, and those will all have DNS records associated, so if you watch our UI build that page with API calls, it also queries for DNS Records so that it can show just the intersection of “is a deployed branch” and “has a DNS record” (probably, one pointing to Netlify and/or that site, though I have not read the code to establish that).

  1. so that call to get the DNS records seems to be:

GET https://api.netlify.com/api/v1/dns_zones/domain_com/dns_records

(note that I used the placeholder “domain_com” - please format your domain like that - _ instead of . in the hostname, when making that call).

That’s about as far as we can guide you; you should be able to write the code from there to do what you want but let us know if you see anything that feels buggy or specific calls not working as you expect (vs what happens when the UI does it)