Dear Netlify Support Team,
I hope this message finds you well.
I am currently leveraging the Netlify API to build websites using subdomains under my primary domain, hejamadi.com, which I fully own. However, I am encountering an issue when attempting to create subdomains with generic names.
Specifically, when I try to publish a site using a generic subdomain such as ball.hejamadi.com
, I receive the following error:
{ subdomain: [ 'must be unique' ] }
In contrast, appending a timestamp to the subdomain name (e.g., ball1736550945554.hejamadi.com
) allows the site to publish successfully without any errors.
Examples:
I have not manually registered the subdomain ball.hejamadi.com
, and I am unsure why it is being flagged as non-unique. Could you please provide guidance on why generic subdomains are not being accepted and advise on how I can resolve this issue to create them without needing to append unique identifiers like Date.now()
?
Thank you for your assistance and support.
@HejSidharth Specifically which API route/method are you running?
I know what you’re doing is setting subdomains off your custom domain, but I’m wondering if the API method is related to the Netlify site name (which is far less likely to be unique).
E.g. This already exists https://ball.netlify.app/
try {
// Deploy to Netlify
console.log("Creating site on Netlify...");
const siteResponse = await axios.post(
"https://api.netlify.com/api/v1/sites",
{
name: subdomain,
custom_domain: `${subdomain}.hejamadi.com`,
force_ssl: true,
},
{
headers: {
Authorization: `Bearer ${NETLIFY_TOKEN}`,
"Content-Type": "application/json",
},
}
);
This is the API method I am using! Also thanks for the help!
@HejSidharth See in your code you have:
name: subdomain,
I’ve not looked at the documentation yet, but I’d imagine that’s doing exactly as I said above.
So to fix you probably just need to ensure the value submitted there is unique.
Here’s some psuedo code to explain what I mean:
{
name: `${subdomain}-hejamadi-com`,
custom_domain: `${subdomain}.hejamadi.com`,
force_ssl: true,
},
You won’t be able to set the site name to 'ball'
since it’s already taken by someone else.
Using your own domain name would be enough to ensure uniqueness, so as a netlify subdomain it would be ball-hejamadi-com.netlify.app
1 Like
Hey Nathan,
Thanks for helping me with the issue, I wasn’t sure if the name of a website had to be unique as I considered it to be a title. Thanks for all the help it works now!
Excellent!
It doesn’t help that the error says:
subdomain: [ 'must be unique' ]
When you haven’t supplied a subdomain
value, it would have been easier to spot with:
name: [ 'must be unique' ]
1 Like