# Add a domain

Registers a domain for the enrolled partner team with an initial status of pending.

Source: https://zerocopy.sh/docs/reference/management-api/add-a-domain

`POST https://console.zerocopy.sh/api/v1/domains`

Authentication: API key, one of: `Authorization: Bearer` header.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Makes a retry return the first successful response instead of adding another domain |

## Request body (`application/json`)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `hostname` | string | yes | maxLength: `253`. pattern: `"^(?!.*\\.zerocopy\\.sh$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.){2,}[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$"`. |
| `target` | `"sol"` or `"fra"` or `"ams"` or `"lon"` or `"nyc"` or `"lax"` or `"tyo"` | yes |  |

```json
{
  "hostname": "send.partner.example",
  "target": "sol"
}
```

## Responses

### 201

The domain and its DNS records

Content type: `application/json`

Both dns_records have type CNAME. The sending record points to `sol.zerocopy.sh` or `<metro>.sol.zerocopy.sh`. The challenge record value is null while preparing, then contains the assigned name under `acme.zerocopy.sh`. See [White label domains](/docs/account/white-label#domains) for setup.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `hostname` | string | yes | maxLength: `253`. pattern: `"^(?!.*\\.zerocopy\\.sh$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.){2,}[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$"`. |
| `target` | `"sol"` or `"fra"` or `"ams"` or `"lon"` or `"nyc"` or `"lax"` or `"tyo"` | yes |  |
| `products` | array of string | yes |  |
| `status` | `"pending"` or `"awaiting_dns"` or `"active"` or `"failed"` | yes |  |
| `acme_dns_fulldomain` | string or null | yes | Assigned challenge target, or null while preparing |
| `not_after` | string (date-time) or null | yes | Certificate expiry timestamp, or null before issuance |
| `last_error` | string or null | yes | Setup or renewal error, or null |
| `created_at` | string (date-time) | yes | RFC 3339 time |
| `updated_at` | string (date-time) | yes | RFC 3339 time |
| `dns_records` | array | yes | minItems: `2`. maxItems: `2`. |
| `dns_records[0]` | object | yes |  |
| `dns_records[0].type` | `"CNAME"` | yes |  |
| `dns_records[0].name` | string | yes |  |
| `dns_records[0].value` | string or null | yes |  |
| `dns_records[1]` | object | yes |  |
| `dns_records[1].type` | `"CNAME"` | yes |  |
| `dns_records[1].name` | string | yes |  |
| `dns_records[1].value` | string or null | yes |  |

```json title="New domain while preparing DNS setup"
{
  "hostname": "send.partner.example",
  "target": "sol",
  "products": [
    "send"
  ],
  "status": "pending",
  "acme_dns_fulldomain": null,
  "not_after": null,
  "last_error": null,
  "created_at": "2026-11-12T09:00:00Z",
  "updated_at": "2026-11-12T09:00:00Z",
  "dns_records": [
    {
      "type": "CNAME",
      "name": "send.partner.example",
      "value": "sol.zerocopy.sh"
    },
    {
      "type": "CNAME",
      "name": "_acme-challenge.send.partner.example",
      "value": null
    }
  ]
}
```

### 400

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Invalid request"
{
  "title": "Bad request",
  "status": 400,
  "code": "invalid_request",
  "detail": "The request does not match the schema.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 401

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Unknown, revoked or expired management key"
{
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The management key is unknown, revoked or expired.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 403

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="IP restriction"
{
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden_ip",
  "detail": "This key does not allow requests from this address.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 404

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Unknown route"
{
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No such route.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 409

The team already has this hostname (`hostname_taken`), its 20-domain limit is reached (`domain_limit`), or an idempotency conflict

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Domain already registered by this team"
{
  "title": "Conflict",
  "status": 409,
  "code": "hostname_taken",
  "detail": "This hostname is already in use.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 413

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Body exceeds the request limit"
{
  "title": "Content too large",
  "status": 413,
  "code": "body_too_large",
  "detail": "The request body exceeds 64 KiB.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

### 429

A refusal; `code` is stable

Content type: `application/problem+json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `title` | string | yes |  |
| `status` | integer | yes | minimum: `-9007199254740991`. maximum: `9007199254740991`. |
| `code` | string | yes | Stable, for programs to branch on |
| `detail` | string | yes |  |
| `request_id` | string | yes |  |
| `errors` | array of object | no |  |
| `errors[].path` | string | yes |  |
| `errors[].message` | string | yes |  |

```json title="Management write limit"
{
  "title": "Too many requests",
  "status": 429,
  "code": "rate_limited",
  "detail": "This key may make 60 such requests a minute.",
  "request_id": "8d4ac3b9-e451-4ca4-9a7f-b3928f0b1672"
}
```

## Code samples

```rust title="Rust"
// src/bin/management_create_domain.rs
// Builds on the example project (/reference/json-rpc#example-project).
use swqos_examples::swqos::{Result, required};

use serde::Serialize;

#[derive(Serialize)]
struct DomainCreate {
    hostname: String,
    target: &'static str,
}

#[tokio::main]
async fn main() -> Result<()> {
    let payload = DomainCreate { hostname: required("DOMAIN_HOSTNAME")?, target: "sol" };
    let endpoint = reqwest::Url::parse("https://console.zerocopy.sh/api/v1/domains")?;
    let request = reqwest::Client::new()
        .post(endpoint)
        .bearer_auth(required("MANAGEMENT_API_KEY")?);
    // Reuse this key and the same body when retrying this creation attempt.
    let request = request.header("Idempotency-Key", required("DOMAIN_REQUEST_ID")?);
    let request = request.json(&payload);
    let response = request.send().await?;
    let status = response.status();
    let request_id = response.headers().get("Request-Id")
        .map(|value| value.to_str()).transpose()?.unwrap_or("<missing>").to_owned();
    if let Some(etag) = response.headers().get("ETag") {
        eprintln!("ETag: {}", etag.to_str()?);
    }
    let body = response.text().await?;
    if !status.is_success() {
        return Err(format!("HTTP {status}; Request-Id: {request_id}; {body}").into());
    }
    eprintln!("Request-Id: {request_id}");
    println!("{body}");
    Ok(())
}
```

```go title="Go"
// management_create_domain/main.go
package main

import (
    "fmt"
    "io"
    "net/http"
    "net/url"
    "os"
    "bytes"
    "encoding/json"
)

type DomainCreate struct {
    Hostname string `json:"hostname"`
    Target string `json:"target"`
}

func required(name string) (string, error) {
    value := os.Getenv(name)
    if value == "" {
        return "", fmt.Errorf("set %s", name)
    }
    return value, nil
}

func run() error {
    apiKey, err := required("MANAGEMENT_API_KEY")
    if err != nil {
        return err
    }
    // Reuse this key and the same body when retrying this creation attempt.
    idempotencyKey, err := required("DOMAIN_REQUEST_ID")
    if err != nil {
        return err
    }
    hostname, err := required("DOMAIN_HOSTNAME")
    if err != nil {
        return err
    }
    payload := DomainCreate{Hostname: hostname, Target: "sol"}
    endpoint, err := url.Parse("https://console.zerocopy.sh/api/v1/domains")
    if err != nil {
        return err
    }
    encoded, err := json.Marshal(payload)
    if err != nil {
        return err
    }
    request, err := http.NewRequest(http.MethodPost, endpoint.String(), bytes.NewReader(encoded))
    if err != nil {
        return err
    }
    request.Header.Set("Authorization", "Bearer "+apiKey)
    request.Header.Set("Idempotency-Key", idempotencyKey)
    request.Header.Set("Content-Type", "application/json")
    response, err := http.DefaultClient.Do(request)
    if err != nil {
        return err
    }
    defer response.Body.Close()
    requestID := response.Header.Get("Request-Id")
    body, err := io.ReadAll(response.Body)
    if err != nil {
        return fmt.Errorf("Request-Id: %s: %w", requestID, err)
    }
    if response.StatusCode < 200 || response.StatusCode >= 300 {
        return fmt.Errorf("HTTP %d; Request-Id: %s; %s", response.StatusCode, requestID, body)
    }
    fmt.Fprintln(os.Stderr, "Request-Id:", requestID)
    if etag := response.Header.Get("ETag"); etag != "" {
        fmt.Fprintln(os.Stderr, "ETag:", etag)
    }
    fmt.Println(string(body))
    return nil
}

func main() {
    if err := run(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}
```

```ts title="TypeScript"
// management-create-domain.ts
export {}

type DomainCreate = { hostname: string; target: 'sol' }

function required(name: string): string {
  const value = process.env[name]
  if (!value) throw new Error(`set ${name}`)
  return value
}

const payload: DomainCreate = { hostname: required('DOMAIN_HOSTNAME'), target: 'sol' }
const endpoint = new URL('https://console.zerocopy.sh/api/v1/domains')
const headers: Record<string, string> = {
  Authorization: `Bearer ${required('MANAGEMENT_API_KEY')}`,
}
// Reuse this key and the same body when retrying this creation attempt.
headers['Idempotency-Key'] = required('DOMAIN_REQUEST_ID')
headers['Content-Type'] = 'application/json'
const response = await fetch(endpoint, { method: 'POST', headers, body: JSON.stringify(payload) })
const requestId = response.headers.get('Request-Id')
const body = await response.text()
if (!response.ok) {
  throw new Error(`HTTP ${response.status}; Request-Id: ${requestId}; ${body}`)
}
console.error('Request-Id:', requestId)
const etag = response.headers.get('ETag')
if (etag) console.error('ETag:', etag)
console.log(body)
```
