Learn how to use Vercel's Domains API to add or remove domains programmatically from your Vercel app.
This template shows how you can use Vercel's Domains API to add and remove domains programmatically from your Vercel app.
Deploy the template using Vercel view the demo, or read the documentation.
You'll need to configure the follow environment variables for this project to work:
PROJECT_ID_VERCEL
: The ID of the Vercel Project you want to add or remove domains from. Lean how to find your Vercel Project ID.TEAM_ID_VERCEL
: The ID of the Vercel Team you want to add or remove domains from. Lean how to find your Vercel Team ID.AUTH_BEARER_TOKEN
: A token that allows programmatic access to your Vercel account. Lean how to create a Vercel Acces Token.To add a domain, you can use the /v8/projects/{idOrName}/domains
endpoint as shown here (full documentation).
When a domain is added, there are 3 possible outcomes:
200
).409
).403
).Verifying a project domain can be done with the /v9/projects/{projectId}/domains/{domain}/verify
endpoint as shown here (full documentation).
When a domain is first added to a project, we use SWR to periodically check if the domain's DNS records are configured correctly. This is done using the /v6/domains/{domain}/config
endpoint as shown here.
There are two ways that your users can configure their domains after they are added:
A
record for the cname
subdomain on your domain and point it to to Vercel's IP address 76.76.21.21
Example:
To remove a domain, you can use the /v8/projects/{idOrName}/domains
endpoint as shown here (full documentation).
You can choose from one of the following methods to use this repository:
Deploy the example using Vercel:
Use create-next-app
to bootstrap the example:
npx create-next-app --example https://github.com/vercel/examples/tree/main/solutions/domains-api domains-api
Then, run Next.js in development mode:
npm run dev
When you're ready to deploy to Vercel, install and use the Vercel CLI to create a new project and deployment.
vercel deploy
Learn how to use Vercel's Domains API to add or remove domains programmatically from your Vercel app.
This template shows how you can use Vercel's Domains API to add and remove domains programmatically from your Vercel app.
Deploy the template using Vercel view the demo, or read the documentation.
You'll need to configure the follow environment variables for this project to work:
PROJECT_ID_VERCEL
: The ID of the Vercel Project you want to add or remove domains from. Lean how to find your Vercel Project ID.TEAM_ID_VERCEL
: The ID of the Vercel Team you want to add or remove domains from. Lean how to find your Vercel Team ID.AUTH_BEARER_TOKEN
: A token that allows programmatic access to your Vercel account. Lean how to create a Vercel Acces Token.To add a domain, you can use the /v8/projects/{idOrName}/domains
endpoint as shown here (full documentation).
When a domain is added, there are 3 possible outcomes:
200
).409
).403
).Verifying a project domain can be done with the /v9/projects/{projectId}/domains/{domain}/verify
endpoint as shown here (full documentation).
When a domain is first added to a project, we use SWR to periodically check if the domain's DNS records are configured correctly. This is done using the /v6/domains/{domain}/config
endpoint as shown here.
There are two ways that your users can configure their domains after they are added:
A
record for the cname
subdomain on your domain and point it to to Vercel's IP address 76.76.21.21
Example:
To remove a domain, you can use the /v8/projects/{idOrName}/domains
endpoint as shown here (full documentation).
You can choose from one of the following methods to use this repository:
Deploy the example using Vercel:
Use create-next-app
to bootstrap the example:
npx create-next-app --example https://github.com/vercel/examples/tree/main/solutions/domains-api domains-api
Then, run Next.js in development mode:
npm run dev
When you're ready to deploy to Vercel, install and use the Vercel CLI to create a new project and deployment.
vercel deploy