
# カスタムドメインをプライマリにする

`POST /v1/custom-domains/{custom_domain_id}:make-primary` · 権限 `custom-domains:write`

ドメインを環境のプライマリカスタムドメインにします (ホストされたサインインのリンクはこのドメインを使います)。以前のプライマリは同じ操作でその役割を外れます。ドメインは `active` である必要があり、すでにプライマリのドメインを再度指定しても何も変わりません。環境の issuer がカスタムドメイン上にある場合、プライマリの変更は issuer を変えるため、issuer の移行としてスケジュールする必要があります。

## リクエスト

| フィールド | タイプ | 必須 | 説明 |
|---|---|---|---|
| `custom_domain_id` | string | はい | カスタムドメイン ID (`cdom_…`)。 |
| `Idempotency-Key` | header | いいえ | リクエストの再試行を安全にする、オプションのキー (16～64 文字)。 |
| `If-Match` | header | いいえ | 任意。指定する場合はドメインの `ETag` と一致する必要があります (一致しなければ `412`)。 |

リクエストボディはありません。

## レスポンス

`200 OK` とドメイン、`ETag` ヘッダー。

```json
{
  "id": "cdom_01j9xk3m7q8r2s4t6v8w0y2z4a",
  "hostname": "login.example.com",
  "is_primary": true,
  "status": "active",
  "failure_reason": null,
  "dns_records": [
    {
      "type": "TXT",
      "name": "_akp-verify.login.example.com",
      "value": "idp-verify=3q2-7wEXAMPLEtokenQ9"
    },
    {
      "type": "CNAME",
      "name": "login.example.com",
      "value": "acme.eu.edge.keenauth.app"
    }
  ],
  "certificate_expires_at": "2027-01-04T09:31:12Z",
  "last_checked_at": "2026-10-05T09:31:00Z",
  "next_check_at": null,
  "activated_at": "2026-10-05T09:31:12Z",
  "degraded_since": null,
  "status_changed_at": "2026-10-05T09:31:12Z",
  "created_at": "2026-10-05T09:30:00.123456Z",
  "updated_at": "2026-10-05T09:31:12Z"
}
```

## エラー

| HTTP | コード | 概要 |
|---|---|---|
| 404 | `not_found` | カスタムドメインが存在しないか、別の環境に属しています。 |
| 409 | `custom_domain_state_conflict` | ドメインが `active` ではありません。 |
| 409 | `issuer_change_requires_schedule` | 環境の issuer がカスタムドメイン上にあります。変更は issuer の移行としてスケジュールする必要があります。 |
| 412 | `precondition_failed` | `If-Match` がドメインの現在のバージョンと一致しません。 |
| 503 | `service_unavailable` | 環境の issuer 情報が一時的に利用できません。 |
| 401 | `unauthenticated` | 認証情報がない、無効、または失効しています。 |
| 403 | `insufficient_permissions` | 認証情報に必要な権限がありません。 |
| 429 | `rate_limited` | レート制限を超えました。`Retry-After` の時間が経過してから再試行してください。 |

## 例

```bash
curl -X POST https://api.eu.keenauth.com/v1/custom-domains/cdom_01j9xk3m7q8r2s4t6v8w0y2z4a:make-primary \
  -H "Authorization: Bearer $KEENAUTH_SECRET_KEY" \
  -H 'If-Match: "4"'
```
