---
raw: true
search:
  tags:
    - Domains
    - POST
seo:
  description: >-
    Attach a hostname to this Space. Spacefast checks the hostname and…
    Reference for the POST /v1/spaces/{spaceId}/domains endpoint in the
    Spacefast API.
sidebar:
  label: Attach a custom domain
  badge: POST
title: Attach a custom domain
type: openapi-operation
---
Attach a hostname to this Space. Spacefast checks the hostname and provisions SSL. Pass `redirect` to answer the hostname with a whole-host redirect instead of serving the Space. If the hostname is attached to another Space, the response is a Spacefast TXT ownership challenge; verifying it moves the attachment after provider cleanup.

`POST /v1/spaces/{spaceId}/domains`

**Request body** (`application/json`, required)

- `name` (string, required) — Hostname to attach. An apex or www hostname also connects its counterpart.
- `primary` (boolean) — Whether this domain becomes the space's primary hostname.
- `redirect` (object | null) — Answer this hostname with a whole-host redirect instead of serving the Space. Omit it, or pass null, to serve the Space.

Request body example:

```json
{
  "name": "string",
  "primary": false,
  "redirect": {
    "to": {
      "url": "http://example.com"
    },
    "status": 308
  }
}
```

**Responses**

- `201` — Response for status 201
- `default` — Problem details (RFC 9457). Any 4xx/5xx response is one \`application/problem+json\` document.

Response example, 201:

```json
{
  "$schema": "http://example.com",
  "data": {
    "wildcardEnabled": true,
    "redirect": {
      "to": {
        "url": "http://example.com"
      },
      "status": 301
    },
    "registrar": {
      "provider": "string",
      "status": "active",
      "expiresAt": "2019-08-24T14:15:22Z",
      "redemptionEndsAt": "2019-08-24T14:15:22Z",
      "autoRenew": true,
      "transferLock": true
    },
    "dns": {
      "managementKind": "unmanaged_external",
      "dnsMode": "authoritative",
      "provider": "string",
      "assignedNameservers": [
        "string"
      ],
      "observedNameservers": [
        "string"
      ],
      "ownershipProof": {
        "type": "A",
        "name": "string",
        "value": "string",
        "ttl": -9007199254740991,
        "purpose": "verification"
      },
      "ownershipVerification": {
        "method": "txt",
        "reason": "conflict",
        "expiresAt": "2019-08-24T14:15:22Z"
      },
      "snapshot": {
        "freshness": "fresh",
        "lastFetchedAt": "2019-08-24T14:15:22Z",
        "version": "string"
      },
      "lastOperation": {
        "id": "string",
        "kind": "string",
        "status": "queued",
        "updatedAt": "2019-08-24T14:15:22Z"
      }
    },
    "hints": [
      {
        "id": "string",
        "code": "string",
        "severity": "info",
        "painLevel": "info",
        "subjectFacet": "dns_zone",
        "subjectRef": {
          "domainId": "string",
          "zoneId": "string",
          "bindingId": "string",
          "connectionId": "string"
        },
        "owner": "spacefast",
        "status": "active",
        "summary": "string",
        "description": "string",
        "impact": "string",
        "evidence": [
          {
            "label": "string",
            "value": "string",
            "observedAt": "2019-08-24T14:15:22Z",
            "source": "provider_api"
          }
        ],
        "suggestions": [
          {
            "label": "string",
            "description": "string",
            "action": {
              "type": "open_pending_action",
              "actionId": "string"
            },
            "primary": true,
            "destructive": true
          }
        ],
        "docsUrl": "http://example.com",
        "operationId": "string",
        "requestId": "string",
        "providerRequestId": "string",
        "expiresAt": "2019-08-24T14:15:22Z"
      }
    ],
    "id": "string",
    "spaceId": "string",
    "name": "string",
    "unicodeName": "string",
    "kind": "hostname",
    "derivedGroup": "string",
    "primary": true,
    "verification": {
      "status": "not_required",
      "requiredRecords": [
        {
          "type": "A",
          "name": "string",
          "value": "string",
          "ttl": -9007199254740991,
          "purpose": "verification"
        }
      ],
      "lastCheckedAt": "2019-08-24T14:15:22Z",
      "lastVerifiedAt": "2019-08-24T14:15:22Z",
      "diagnostics": [
        {
          "code": "string",
          "severity": "info",
          "message": "string",
          "path": "string",
          "provider": "infra",
          "details": {
            "property1": null,
            "property2": null
          },
          "fix": "string",
          "retryable": true
        }
      ]
    },
    "servingRecords": {
      "source": "spacefast_dns",
      "zone": {
        "hostname": "string",
        "status": "served"
      },
      "names": [
        {
          "name": "string",
          "state": "served",
          "records": [
            {
              "type": "A",
              "name": "string",
              "value": "string",
              "ttl": -9007199254740991,
              "purpose": "verification"
            }
          ],
          "blocking": [
            {
              "id": "string",
              "type": "A",
              "name": "string",
              "value": "string"
            }
          ]
        }
      ]
    },
    "ownership": {
      "status": "verification_required",
      "expiresAt": "2019-08-24T14:15:22Z",
      "moveAvailable": true
    },
    "source": "custom",
    "managed": false,
    "deletable": true,
    "assignable": true,
    "createdAt": "2019-08-24T14:15:22Z",
    "updatedAt": "2019-08-24T14:15:22Z"
  },
  "operation": {
    "id": "string",
    "kind": "string",
    "status": "queued",
    "resources": [
      {
        "type": "string",
        "id": "string"
      }
    ],
    "progress": {
      "total": 0,
      "completed": 0,
      "failed": 0
    },
    "diagnostics": [
      {
        "code": "string",
        "severity": "info",
        "message": "string",
        "path": "string",
        "provider": "infra",
        "details": {
          "property1": null,
          "property2": null
        },
        "fix": "string",
        "retryable": true
      }
    ],
    "createdAt": "2019-08-24T14:15:22Z",
    "finishedAt": "2019-08-24T14:15:22Z"
  }
}
```
