Learn to leverage Vercel's Domains API to add and remove domains programmatically from your Platforms on Vercel project.
This code snippet shows you how you can leverage Vercel's Domains API to add and remove domains programmatically from your Platforms on Vercel project.
npm install tailwindcss
)npm install swr
)npm install react-hot-toast
) (optional)npm install js-cookie
) (optional)https://domains-api.vercel.app/
You'll need to configure 3 different environment variables for this project to work:
PROJECT_ID_VERCEL
: The ID of the Vercel project you want to add/remove domains from. You can find it under the "Settings" tab in your project's dashboard.TEAM_ID_VERCEL
: The ID of the Vercel team you want to add/remove domains from. You can find it under the "Settings" tab in your team's dashboard.AUTH_BEARER_TOKEN
: Your personal auth bearer token that gives you programmatic access to your Vercel account. You can create one under the "Tokens" tab in your personal account's settings tab.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 two methods to use this repository:
Deploy the example using Vercel:
Execute create-next-app
with pnpm to bootstrap the example:
pnpm create next-app --example https://github.com/vercel/examples/tree/main/solutions/domains-api domains-api
Next, run Next.js in development mode:
pnpm dev
Deploy it to the cloud with Vercel (Documentation).
Learn to leverage Vercel's Domains API to add and remove domains programmatically from your Platforms on Vercel project.
This code snippet shows you how you can leverage Vercel's Domains API to add and remove domains programmatically from your Platforms on Vercel project.
npm install tailwindcss
)npm install swr
)npm install react-hot-toast
) (optional)npm install js-cookie
) (optional)https://domains-api.vercel.app/
You'll need to configure 3 different environment variables for this project to work:
PROJECT_ID_VERCEL
: The ID of the Vercel project you want to add/remove domains from. You can find it under the "Settings" tab in your project's dashboard.TEAM_ID_VERCEL
: The ID of the Vercel team you want to add/remove domains from. You can find it under the "Settings" tab in your team's dashboard.AUTH_BEARER_TOKEN
: Your personal auth bearer token that gives you programmatic access to your Vercel account. You can create one under the "Tokens" tab in your personal account's settings tab.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 two methods to use this repository:
Deploy the example using Vercel:
Execute create-next-app
with pnpm to bootstrap the example:
pnpm create next-app --example https://github.com/vercel/examples/tree/main/solutions/domains-api domains-api
Next, run Next.js in development mode:
pnpm dev
Deploy it to the cloud with Vercel (Documentation).