Unable to add domain via API

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

Thanks for the details, I’ve passed this on to the Domains team

Looks like this query should work if you remove the gitBranch from your submission but they’ll look into making this API more resilient to different arguments

2 Likes

Thanks Jacob, that’s fixed my issue.

1 Like

Awesome, thanks for confirming

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.