> ## Documentation Index
> Fetch the complete documentation index at: https://docs.scanova.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 更新自定义域名

> PATCH /custom-domain/{pk}/

在 **Management API** 主机（`api.scanova.io`）上更新自定义域名的配置，使用您的原始 Management API 密钥进行身份验证。

```
PUT   https://api.scanova.io/custom-domain/{pk}/
PATCH https://api.scanova.io/custom-domain/{pk}/
Authorization: 401f7ac837da42b97f613d789819ff93537bee6a
```

<ParamField path="pk" type="integer" required>
  域名的 `id`。
</ParamField>

<ParamField body="is_default" type="boolean">
  新的 QR 码是否默认使用此域名。
</ParamField>

<ParamField body="root_action" type="string">
  当有人访问裸域名（不带 QR slug）时该执行的操作：`no_action`（默认）、`url_redirect` 或 `custom_page`。
</ParamField>

<ParamField body="redirect" type="string">
  当 `root_action` 为 `url_redirect` 时，将访客发送到的 URL。
</ParamField>

<ParamField body="template" type="integer">
  当 `root_action` 为 `custom_page` 时用作根页面的 `CustomDomainTemplate` id——参见[列出自定义域名根页面模板](/zh/api-reference/management-api/custom-domain/templates-list)。
</ParamField>

<ParamField body="protocol" type="string">
  `none`、`http` 或 `https`。留空时默认为 `https`。
</ParamField>

<ParamField body="remove_qr_query" type="boolean">
  设置后会从短链接 URL 中去除 `?qr=1` 跟踪参数。
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X PATCH "https://api.scanova.io/custom-domain/42/" \
    -H "Authorization: 401f7ac837da42b97f613d789819ff93537bee6a" \
    -H "Content-Type: application/json" \
    -d '{
      "root_action": "url_redirect",
      "redirect": "https://example.com/landing"
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": 42,
    "domain": "https://links.example.com",
    "is_default": false,
    "disable_slug_case": false,
    "txt_value": "scanova-verification=abc123...",
    "is_txt_verified": true,
    "is_cname_verified": true,
    "is_migrated": false,
    "dns_provider": { "name": "Cloudflare", "placeholders": { "cname": { "content": { "label": "Target" } } } },
    "txt_error": null,
    "cname_error": null,
    "root_action": "url_redirect",
    "redirect": "https://example.com/landing",
    "template": null,
    "protocol": "https",
    "remove_qr_query": false,
    "cname_target": "shortcname.scanova.io",
    "domain_connect_supported": false,
    "domain_connect_checked_at": null,
    "created": "2026-09-08T10:00:00Z",
    "modified": "2026-09-08T10:00:00Z"
  }
  ```
</ResponseExample>

## 大多数字段在此端点为只读

只有 `is_default`、`root_action`、`redirect`、`template`、`protocol` 和 `remove_qr_query` 可以通过此端点写入——其他所有字段，包括 `domain` 本身，一旦域名创建后即为只读。如果 `pk` 不是该账户拥有的域名，则返回 `404`。

## 相关内容

* [获取自定义域名](/zh/api-reference/management-api/custom-domain/retrieve)——更新前先查看。
* [列出自定义域名根页面模板](/zh/api-reference/management-api/custom-domain/templates-list)——为 `custom_page` 查找 `template` id。
* [Management API 概览](/zh/api-reference/management-api/overview)——适用于此端点的身份验证方案和配额规则。


## OpenAPI

````yaml api-reference/openapi/management-api.json PATCH /custom-domain/{pk}/
openapi: 3.1.0
info:
  title: Scanova Management API (v2)
  description: >-
    The complete Scanova Management API — every endpoint available at
    api.scanova.io (QR codes, folders, tags, leads, forms, analytics, plans,
    shared users & roles), plus the token-creation and usage-stats endpoints
    used to authenticate against it. Every path and request/response shape below
    was verified live against a real API key and the actual running backend
    (Phase 7, 2026-08-16) — not guessed from reading urls.py alone.
  version: 2.0.0
servers:
  - url: https://api.scanova.io
    description: Management API — QR/folder/tag/lead/form/analytics/plans endpoints
security:
  - apiKeyAuth: []
paths:
  /custom-domain/{pk}/:
    patch:
      summary: Update a custom domain
      description: >-
        Both PUT and PATCH are supported. Only `is_default`, `root_action`,
        `redirect`, `template`, `protocol`, and `remove_qr_query` are writable
        here — every other field (including `domain` itself) is read-only on
        update.
      operationId: updateCustomDomain
      parameters:
        - name: pk
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        content:
          application/json:
            example:
              root_action: url_redirect
              redirect: https://example.com/landing
      responses:
        '200':
          description: Domain updated.
          content:
            application/json:
              example:
                id: 42
                domain: https://links.example.com
                is_default: false
                disable_slug_case: false
                txt_value: scanova-verification=abc123...
                is_txt_verified: false
                is_cname_verified: false
                is_migrated: false
                dns_provider:
                  name: Cloudflare
                  placeholders:
                    cname:
                      content:
                        label: Target
                txt_error: null
                cname_error: null
                root_action: url_redirect
                redirect: https://example.com/landing
                template: null
                protocol: https
                remove_qr_query: false
                cname_target: shortcname.scanova.io
                domain_connect_supported: false
                domain_connect_checked_at: null
                created: '2026-09-08T10:00:00Z'
                modified: '2026-09-08T10:00:00Z'
        '404':
          description: No domain with this id owned by this account.
components:
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Send your Management API key as the raw value of the Authorization
        header — no "Bearer " or "Token " prefix, and no other characters.
        Example: `Authorization: 401f7ac837da42b97f613d789819ff93537bee6a`. A
        header containing more than one space-separated part is rejected
        outright. Requests also require the request's Host header to be the
        management API host (e.g. api.scanova.io) — the same key sent to the
        regular API host will not authenticate.

````