I’m running a multi-tenant app, similar approach to the platform starter kit: Platforms Starter Kit.
Users go through a signup flow, and then I send a request via the Vercel projects API to associate the new tenant subdomain with my existing project.
This functionality was working at one point, but it now appears to be broken.
Current behaviour
The domain is not added to the project and I receive an error.
I call the ‘Add a domain to a project’ API
Fetch URL: https://api.vercel.com/v10/projects/xxx/domains?teamId=yyy
Fetch Body: {“name”:“lilac.swiftplan.io”,“gitBranch”:“main”}
Fetch Headers: {
Authorization: ‘Bearer XXX’,
‘Content-Type’: ‘application/json’
}
Fetch Method: POST
I receive the following error:
{
error: {
code: 'cannot_set_production_branch_as_preview',
message: 'Cannot set Production Branch "main" for a Preview Domain.',
action: 'Learn More',
link: 'https://vercel.link/production-branch-as-preview-branch'
}
}
I don’t understand why it is states the subdomain here is a ‘preview’ branch. If I add the domain manually via the Vercel UI it works as expected.
Do you have any ideas how I can resolve this?
Thanks
Arthur