Skip to content
Avatar of vercelvercel/examples

Domains API

Learn how to use Vercel's Domains API to add or remove domains programmatically from your Vercel app.

Framework
Domains API

Domains API

This template shows how you can use Vercel's Domains API to add and remove domains programmatically from your Vercel app.

Deploy your own

Deploy the template using Vercel view the demo, or read the documentation.

Features

1. Configure Environment Variables

You'll need to configure the follow environment variables for this project to work:

2. Adding Domains

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:

  1. Domain is added successfully (response code 200).
  2. Domains is already in use by another project and can't be added (response code 409).
  3. Domains belongs to a different team but you can potentially request delegation for the domain (response code 403).
Verifying Project Domain

Verifying a project domain can be done with the /v9/projects/{projectId}/domains/{domain}/verify endpoint as shown here (full documentation).

3. Auto-checking Domain Configuration

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:

  • CNAME record:
    • recommended for subdomains (blog.domain.com, app.domain.com)
    • you can set up a branded CNAME value by adding an A record for the cname subdomain on your domain and point it to to Vercel's IP address 76.76.21.21
  • A record:
    • recommended for apex domains (domain.com)

Example:

4. Removing Domains

To remove a domain, you can use the /v8/projects/{idOrName}/domains endpoint as shown here (full documentation).

How to Use

You can choose from one of the following methods to use this repository:

One-Click Deploy

Deploy the example using Vercel:

Clone and Deploy

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
Domains API
Avatar of vercelvercel/examples

Domains API

Learn how to use Vercel's Domains API to add or remove domains programmatically from your Vercel app.

Framework

Domains API

This template shows how you can use Vercel's Domains API to add and remove domains programmatically from your Vercel app.

Deploy your own

Deploy the template using Vercel view the demo, or read the documentation.

Features

1. Configure Environment Variables

You'll need to configure the follow environment variables for this project to work:

2. Adding Domains

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:

  1. Domain is added successfully (response code 200).
  2. Domains is already in use by another project and can't be added (response code 409).
  3. Domains belongs to a different team but you can potentially request delegation for the domain (response code 403).
Verifying Project Domain

Verifying a project domain can be done with the /v9/projects/{projectId}/domains/{domain}/verify endpoint as shown here (full documentation).

3. Auto-checking Domain Configuration

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:

  • CNAME record:
    • recommended for subdomains (blog.domain.com, app.domain.com)
    • you can set up a branded CNAME value by adding an A record for the cname subdomain on your domain and point it to to Vercel's IP address 76.76.21.21
  • A record:
    • recommended for apex domains (domain.com)

Example:

4. Removing Domains

To remove a domain, you can use the /v8/projects/{idOrName}/domains endpoint as shown here (full documentation).

How to Use

You can choose from one of the following methods to use this repository:

One-Click Deploy

Deploy the example using Vercel:

Clone and Deploy

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

Unleash New Possibilities

Deploy your app on Vercel and unlock its full potential