---
title: "Attach a custom domain to a site"
method: POST
path: "/sites/{siteId}/custom-domains"
tags: ["Custom Domains"]
---

# Attach a custom domain to a site

`POST /sites/{siteId}/custom-domains`

## Request

- Base URL: `https://api.nippy.host`
- URL: `https://api.nippy.host/sites/{siteId}/custom-domains`
- Auth: `bearer` (a scheme the document does not define)

Validates the hostname, registers a Cloudflare Custom Hostname under our SaaS zone, and returns the row in `pending_dns`. The customer completes setup by adding a single CNAME record.

## Path parameters

- `siteId` string, required

## Request body

- AddCustomDomainDto
  - `hostname` string, required: Domain to attach. Apex (example.com) and subdomain (www.example.com) forms are both accepted. The www. companion is auto-attached for apex inputs.

## Response `201`

- APICustomDomain
  - `id` string, required
  - `hostname` string, required
  - `status` 'pending_dns' | 'pending_ssl' | 'active' | 'failed' | 'disabled', required: pending_dns: waiting on customer to add CNAME. pending_ssl: CNAME good, certificate provisioning. active: serving public traffic. failed: terminal — see failureReason. disabled: user-disabled, retained for re-enable.
  - `failureReason` string, nullable: Stable machine-readable failure code when status=failed; null otherwise. Examples: `hostname_in_use`, `cert_validation_failed`, `timeout`.
  - `publicUrl` string, required
  - `expectedCname` string, required: CNAME instructions to surface to the customer. Same value for every domain on the platform — set once at the zone level.
  - `dnsRecordName` string, required: The "Host"/"Name" value to enter in the CNAME record at the DNS provider — the label(s) left of the registrable domain. "@" marks the root for an apex. Many providers want this rather than the full hostname, so the UI shows it alongside `hostname` as a fallback.
  - `dnsPreflight` APIDnsPreflight, required
    - `expectedTarget` string, required: CNAME target the customer should add.
    - `observedTarget` string, nullable: CNAME target observed in DNS, if any.
    - `ok` boolean, required: True if the observed target matches the expected target.
  - `ownershipTxt` object
    - `name` string, required
    - `value` string, required
  - `verifiedAt` string, date-time, nullable
  - `createdAt` string, date-time, required
  - `updatedAt` string, date-time, required
  - `parentDomainId` string, nullable: When this row was auto-created (the www. companion of an apex), this is the apex row id; users can manage both via the apex.

## Other responses

- `400`: Hostname invalid or reserved
- `401`: Not authenticated
- `403`: You do not own this site
- `409`: Hostname is already attached to another site

---

[API](https://skmtc.dev/nippy/apis/nippy-backend-api.md) · [All operations](https://skmtc.dev/nippy/apis/nippy-backend-api/llms.txt) · [OpenAPI document](https://skmtc.dev/nippy/apis/nippy-backend-api/revisions/7ab23f040a55?raw)
