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

# 更新问卷 API：编辑 KYC 表单

> 使用 Didit 编辑 KYC 问卷：重命名、替换有序问题、刷新多语言标签。以编程方式管理合规表单，按次计费。



更新问卷 API 提示词
        将提示词复制到剪贴板



      
      

\<pre>

\`Update a simple Didit questionnaire through the Management API.

Endpoint:
PATCH https://verification.didit.me/v3/questionnaires/{questionnaire_uuid}/

Authentication:
Use the x-api-key header with my Didit API key.

Requirements:
\- Use PATCH and include only the fields I want to change.
\- To rename the questionnaire, send title or description only.
\- To change questions, send the full desired form_elements array. This replaces the existing question list.
\- Do not send graph, branches, next, required_if, or conditional logic.
\- Keep languages consistent with the questionnaire. Include en labels for every form element.
\- Capture the questionnaire_id returned by the response because published updates may return a new version id.

Example metadata update body:
\{
"title": "Updated Customer Onboarding"
}

Example full question replacement body:
\{
"form_elements": [
\{
  "id": "occupation",
  "element_type": "short_text",
  "label": { "en": "What is your occupation?" },
  "is_required": true
},
\{
  "id": "source_of_funds",
  "element_type": "multiple_choice",
  "label": { "en": "Source of funds" },
  "options": [
    \{ "value": "employment", "label": { "en": "Employment" } },
    \{ "value": "business", "label": { "en": "Business" } }
  ]
}
]
}

Build the API call, handle validation errors, and return the latest questionnaire_id from the response.`

\</pre>



      
      

粘贴到

对部分更新请使用 `PATCH`。若要重命名问卷，只需发送 `title` 或 `description`。```json theme={null}
{
  "title": "Updated Customer Onboarding"
}
```若要更新问题，请发送完整的目标 `form_elements` 数组。这会替换之前的问题列表。如果仍需显示某些现有问题，请将其保留在数组中。```json theme={null}
{
  "form_elements": [
    {
      "id": "occupation",
      "element_type": "short_text",
      "label": { "en": "What is your occupation?" },
      "is_required": true
    },
    {
      "id": "source_of_funds",
      "element_type": "multiple_choice",
      "label": { "en": "Source of funds" },
      "options": [
        { "value": "employment", "label": { "en": "Employment" } },
        { "value": "business", "label": { "en": "Business" } }
      ]
    }
  ]
}
```v3 API 仅支持简单的线性问卷。它会拒绝 `graph`、`branches`、`next` 以及条件规则。响应中包含 `questionnaire_id`。更新 `published` 状态的问卷时，API 可能会创建新版本。请保存返回的 `questionnaire_id`，并在工作流中使用它，而不要假定 URL 中的 id 仍是最新版本。


## OpenAPI

````yaml zh/openapi-25.json PATCH /v3/questionnaires/{questionnaire_uuid}/
openapi: 3.0.0
info:
  version: 3.0.0
  title: Didit Verification API
  description: 身份证件验证 API。使用 x-api-key 请求头进行身份验证。
servers:
  - url: https://verification.didit.me
security: []
tags: []
paths:
  /v3/questionnaires/{questionnaire_uuid}/:
    patch:
      tags:
        - Questionnaires
      summary: 更新问卷
      description: >-
        更新问卷。版本控制取决于您发送的 `status` 字段以及该版本的当前状态：(1) **已发布**版本未传 `status` →
        已发布版本就地更新（相同的 `questionnaire_id`，相同的 `version`）；(2) **草稿**未传 `status` →
        草稿更新并立即发布；(3) **已发布**版本传入 `status: "published"` → 在同一个
        `questionnaire_group_id` 下创建并返回一个新的已发布版本（新的 `questionnaire_id`，`version`
        + 1），并删除该分组中现有的任何草稿；(4) `status: "draft"`
        将草稿保持为草稿（自动保存），但若在已发布版本上操作则会被拒绝并返回 400（`"Cannot revert a published
        version to draft."`）。
      operationId: update_questionnaire
      parameters:
        - name: questionnaire_uuid
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: 要更新的问卷版本 UUID。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SimpleQuestionnaireUpdateRequest'
            examples:
              Rename:
                summary: 重命名问卷
                value:
                  title: Updated Customer Onboarding
              Replace questions:
                summary: 替换完整的线性问题列表
                value:
                  form_elements:
                    - id: occupation
                      element_type: short_text
                      label:
                        en: What is your occupation?
                      is_required: true
                    - id: source_of_funds
                      element_type: multiple_choice
                      label:
                        en: Source of funds
                      options:
                        - value: employment
                          label:
                            en: Employment
                        - value: business
                          label:
                            en: Business
      responses:
        '200':
          description: >-
            问卷已更新。body 是生成版本的最新状态 — 就地更新的版本，或者当您在已发布行上发送 `status: "published"`
            时新创建的已发布版本（在该情况下，`questionnaire_id` 和 `version` 与您打补丁的版本不同）。响应中的
            `questionnaire_id` 是每个版本的 UUID；如果您需要稳定的组标识符，请使用
            `questionnaire_group_id`。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QuestionnaireDetail'
        '400':
          description: >-
            验证错误 — 未知的 `element_type`、缺少翻译、不支持的分支/条件字段、`languages` 中缺少
            `en`、`default_language` 不在 `languages` 中、选项缺少标签、发送了原始
            `graph`，或在已发布版本上设置 `status: "draft"`（`"Cannot revert a published
            version to draft."`）。响应体是以字段名为键的 DRF 验证错误。
        '403':
          description: API 密钥缺失或无效。
          content:
            application/json:
              examples:
                Invalid token:
                  value:
                    detail: You do not have permission to perform this action.
        '404':
          description: 已验证身份的应用中不存在具有此 `questionnaire_uuid` 的问卷。
        '415':
          description: '不支持的媒体类型。请设置 `Content-Type: application/json`。'
        '429':
          description: 超出速率限制。请使用指数退避重试。
        '500':
          description: 意外服务器错误。可安全重试。
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: curl
          label: cURL
          source: >-
            curl -X PATCH
            'https://verification.didit.me/v3/questionnaires/11111111-2222-3333-4444-555555555555/'
            \
              -H 'x-api-key: YOUR_API_KEY' \
              -H 'Content-Type: application/json' \
              -d '{"title": "Updated Customer Onboarding"}'
        - lang: python
          label: Python
          source: |-
            from didit import Didit

            # Reads DIDIT_API_KEY.
            client = Didit()

            result = client.questionnaires.update(
                "11111111-2222-3333-4444-555555555555",
                title="Updated Customer Onboarding",
            )
            print(result)
        - lang: javascript
          label: Node.js
          source: >-
            import Didit from "@didit-protocol/sdk-node";


            // Reads DIDIT_API_KEY.

            const didit = new Didit();


            const result = await
            didit.questionnaires.update("11111111-2222-3333-4444-555555555555",
            {
              title: "Updated Customer Onboarding",
            });

            console.log(result);
        - lang: go
          label: Go
          source: "ctx := context.Background()\n// Reads DIDIT_API_KEY.\nclient := didit.NewClient()\n\nresult, err := client.Questionnaires.Update(ctx, \"11111111-2222-3333-4444-555555555555\", didit.SimpleQuestionnaireUpdateRequest{\n\tTitle: didit.String(\"Updated Customer Onboarding\"),\n})\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"%+v\\n\", result)"
        - lang: java
          label: Java
          source: >-
            import me.didit.Didit;

            import me.didit.types.SimpleQuestionnaireUpdateRequest;


            // Reads DIDIT_API_KEY.

            Didit client = new Didit();


            var result =
            client.questionnaires().update("11111111-2222-3333-4444-555555555555",
            SimpleQuestionnaireUpdateRequest.builder()
                    .title("Updated Customer Onboarding")
                    .build());
            System.out.println(result);
        - lang: php
          label: PHP
          source: >-
            <?php


            require 'vendor/autoload.php';


            use Didit\DiditClient;


            // Reads DIDIT_API_KEY.

            $didit = new DiditClient();


            $result =
            $didit->questionnaires->update('11111111-2222-3333-4444-555555555555',
            [
                'title' => 'Updated Customer Onboarding',
            ]);

            print_r($result->toArray());
        - lang: ruby
          label: Ruby
          source: |-
            require "didit"

            # Reads DIDIT_API_KEY.
            didit = Didit::Client.new

            result = didit.questionnaires.update(
              "11111111-2222-3333-4444-555555555555",
              title: "Updated Customer Onboarding"
            )
            puts result.to_h
        - lang: csharp
          label: .NET
          source: >-
            using System;

            using System.Text.Json;

            using Didit;


            // Reads DIDIT_API_KEY.

            using var client = new DiditClient();


            var result = await
            client.Questionnaires.UpdateAsync("11111111-2222-3333-4444-555555555555",
            new SimpleQuestionnaireUpdateRequest

            {
                Title = "Updated Customer Onboarding",
            });

            Console.WriteLine(JsonSerializer.Serialize(result));
components:
  schemas:
    SimpleQuestionnaireUpdateRequest:
      type: object
      description: 更新问卷元数据或替换完整的线性 `form_elements` 列表。
      properties:
        title:
          type: string
        description:
          type: string
          nullable: true
        languages:
          type: array
          items:
            type: string
        default_language:
          type: string
        is_active:
          type: boolean
        status:
          type: string
          enum:
            - draft
            - published
        form_elements:
          type: array
          minItems: 1
          description: 如果提供，将替换完整的线性问题列表。
          items:
            $ref: '#/components/schemas/SimpleQuestionnaireElement'
    QuestionnaireDetail:
      type: object
      description: 从 GET、POST（创建）和 PATCH（更新）endpoint 返回的完整问卷详情。
      properties:
        questionnaire_id:
          type: string
          format: uuid
          description: 问卷的唯一标识符。在工作流中引用该问卷或在后续更新/删除请求中使用此 ID。
        title:
          type: string
        description:
          type: string
          nullable: true
        languages:
          type: array
          items:
            type: string
        default_language:
          type: string
        is_active:
          type: boolean
        is_simple_questionnaire:
          type: boolean
        graph:
          type: object
          description: 包含 start_node 和 nodes 映射的图谱结构。
        sections:
          type: array
          description: 分组到各节中的问卷内容（源自图谱）。
          items:
            type: object
        questionnaire_group_id:
          type: string
          format: uuid
          description: 用于将同一问卷的所有版本分组的稳定标识符。
        version:
          type: integer
        status:
          type: string
          enum:
            - draft
            - published
        published_at:
          type: string
          format: date-time
          nullable: true
        is_editable:
          type: boolean
          description: 当问卷仍可就地编辑（草稿版本）时为 true。
    SimpleQuestionnaireElement:
      type: object
      required:
        - element_type
        - label
      properties:
        id:
          type: string
          description: 可选的稳定问题 ID。如果省略，API 将生成 `q1`、`q2` 等。为确保可读性，请使用小写字母、数字和下划线。
          example: source_of_funds
        element_type:
          type: string
          description: 问题类型。API 接受这些小写值及其对应的大写形式。
          enum:
            - short_text
            - long_text
            - dropdown
            - single_choice
            - multiple_choice
            - number
            - image
            - file_upload
            - time
            - email
            - address
            - phone
            - country
            - date_picker
            - consent
            - section_header
            - separator
            - heading
            - paragraph
        label:
          type: object
          description: '按语言代码划分的问题标签，例如 `{ "en": "Source of funds" }`。'
          additionalProperties:
            type: string
        description:
          type: object
          nullable: true
          additionalProperties:
            type: string
        placeholder:
          type: object
          nullable: true
          additionalProperties:
            type: string
        is_required:
          type: boolean
          default: false
        options:
          type: array
          description: >-
            用于 `dropdown`、`single_choice` 和 `multiple_choice`。如果省略 `value`，API
            会根据选项标签生成一个值。
          items:
            type: object
            required:
              - label
            properties:
              value:
                type: string
              label:
                type: object
                additionalProperties:
                  type: string
        max_files:
          type: integer
          minimum: 1
          maximum: 5
          description: 与 `file_upload` 或 `image` 一起使用。
        validation:
          type: object
          nullable: true
          description: >-
            针对 `short_text`、`long_text` 或 `number`
            的可选格式验证。在用户填写字段时强制执行（验证通过后方可继续），并在提交时由 API 重新检查。
          properties:
            pattern:
              type: string
              description: >-
                该值必须完全匹配的正则表达式（ECMA-262 子集）。适用于 `short_text` 和 `long_text`。请勿添加
                ^/$ 锚点；系统将对整个值进行匹配。
            min_length:
              type: integer
              minimum: 0
              description: 最小字符数。适用于 `short_text` 和 `long_text`。
            max_length:
              type: integer
              minimum: 0
              description: 最大字符数。适用于 `short_text` 和 `long_text`。
            min:
              type: number
              description: 最小数值。适用于 `number`。
            max:
              type: number
              description: 最大数值。适用于 `number`。
            error_message:
              type: object
              description: 验证失败时显示的已翻译消息，以语言代码为键。
              additionalProperties:
                type: string
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        您的应用 API 密钥，可在 Business Console 的“开发者 -> API
        密钥”中获取。主密钥拥有完整访问权限。指定名称的密钥可设置作用域：针对每个资源设为无权限、只读或读写，限定于特定工作流或已通过的会话、限定于
        IP 地址列表，以及设置到期日期。401 表示密钥错误、已撤销或已过期；403 表示未发送密钥、密钥无权访问该资源或操作，或请求来自其 IP
        列表之外的地址；在会话路由上返回 404 表示该会话不在该密钥允许的工作流或状态范围内。没有媒体访问权限的密钥获取到的图片、视频和 PDF
        URL 将为 null；没有会话写入权限的密钥获取到的会话链接和 token 将为 null。请参阅
        https://docs.didit.me/console/api-keys。

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.