Support Forums

Set alias as primary domain via API


Is it possible to set a custom domain / alias as a primary domain via Netlify API? Couldn’t found anything about this in the docs.

hi there, can you say a little more what you mean by ‘primary domain’? i want to make sure i understand correctly before i give advice, thanks!

Hi @Wdotis,

Are you wanting to add example.com as a custom domain with www.example.com and an alias to your reallycoolwebsite.netlify.app?

If so, yes, you can do this via the API. Try createDNSZone then createDNSRecord then configureDNSForSite then updateSite.

That’s what worked for me at least. :smiley:

CleanShot 2021-06-18 at 18.03.37

Hi, it means the default domain name in Netlify settings.

Thank you. I’ll try this, however it shouldn’t be an alias but the primary domain!

Hi, @Wdotis. My recommendation is always do make the change in the web UI and to then look at the browser devtools to see the API calls made to make the change.

This will show you exactly how to make the required API calls. We have a support guide about using devtools to examine the API here:

Here is an example of making the API call using curl:

curl 'https://api.netlify.com/api/v1/sites/hiretable'  \
 -X PUT -H 'Content-Type: application/json' \
-H 'Authorization: Bearer <YOUR_TOKEN_GOES_HERE>' \
--data-raw '{"custom_domain":"hiretable.io"}'

If there are other questions, please let us know.

1 Like