> ## 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 与合规问卷，支持有序问题、选项及 54 种语言翻译。按次计费。



创建问卷 API 提示词
        将提示词复制到剪贴板



      
      

\<pre>

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

Endpoint:
POST https://verification.didit.me/v3/questionnaires/

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

Requirements:
\- Use the simple v3 API shape with form_elements.
\- Do not send graph, branches, next, required_if, or conditional logic.
\- Include languages with en and default_language set to en.
\- Use customer-friendly element_type values such as short_text, multiple_choice, email, file_upload, or date_picker.
\- For choice questions, send options with value and label.
\- Store the questionnaire_id from the response because I will use it later as questionnaire_uuid in workflows.

Example request body:
\{
"title": "Customer Onboarding",
"languages": ["en"],
"default_language": "en",
"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" },
  "is_required": true,
  "options": [
    \{ "value": "employment", "label": { "en": "Employment" } },
    \{ "value": "business", "label": { "en": "Business" } },
    \{ "value": "investments", "label": { "en": "Investments" } }
  ]
}
]
}

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

\</pre>



      
      

粘贴到

使用此 endpoint 通过 API 创建简单问卷。按用户应回答问题的顺序发送 `form_elements` 数组。Didit 会为您构建内部问卷图谱。该 API 仅支持简单的线性问卷。请勿发送 `graph`、`branches`、`next` 或条件规则。## 必填字段- `title` 是内部问卷名称。
- `languages` 必须包含 `en`。
- `form_elements` 必须至少包含一个问题。
- 每个表单元素都需要 `element_type` 和已翻译的 `label`。您还可以为表单元素添加可选的已翻译 `description`，作为其帮助文本。除 `separator` 外，所有元素类型都支持该字段，并会在[问卷报告](https://docs.didit.me/zh/core-technology/questionnaires/report-questionnaire.md)中以该条目的 `description` 返回。## 元素类型请使用小写值，例如 `short_text`、`multiple_choice`、`email`、`file_upload` 或 `date_picker`。大写枚举值（例如 `SHORT_TEXT`）也可以使用。对于 `dropdown`、`single_choice` 和 `multiple_choice`，请添加 `options`。如果省略选项的 `value`，Didit 会根据标签自动生成。```json theme={null}
{
  "title": "Customer Onboarding",
  "languages": ["en"],
  "default_language": "en",
  "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" },
      "is_required": true,
      "options": [
        { "value": "employment", "label": { "en": "Employment" } },
        { "value": "business", "label": { "en": "Business" } },
        { "value": "investments", "label": { "en": "Investments" } }
      ]
    }
  ]
}
```## 字段验证为 `short_text`、`long_text` 或 `number` 元素添加可选的 `validation` 对象，即可对用户的回答强制执行格式。这对于有严格格式要求的标识符很有用，例如税号、国民身份证号或卡号。用户填写字段时即会进行验证（未通过验证时用户无法继续），提交时 API 还会再次强制执行。| 字段 | 适用于 | 说明 |
| - | - | - |
| `pattern` | `short_text`、`long_text` | 值必须完整匹配的正则表达式。请使用可移植的 ECMA-262 子集，不要添加 `^`/`$` 锚点（整个值都会被匹配）。 |
| `min_length` | `short_text`、`long_text` | 最少字符数。 |
| `max_length` | `short_text`、`long_text` | 最多字符数。 |
| `min` | `number` | 最小数值。 |
| `max` | `number` | 最大数值。 |
| `error_message` | 以上所有字段 | 值未通过验证时显示的已翻译消息。省略时使用通用消息。 |```json theme={null}
{
  "title": "Customer Onboarding",
  "languages": ["en"],
  "default_language": "en",
  "form_elements": [
    {
      "id": "tax_id",
      "element_type": "short_text",
      "label": { "en": "Tax ID" },
      "is_required": true,
      "validation": {
        "pattern": "[A-Z]{2}[0-9]{9}",
        "min_length": 11,
        "max_length": 11,
        "error_message": { "en": "Enter a valid Tax ID (2 letters followed by 9 digits)." }
      }
    }
  ]
}
```响应中包含 `questionnaire_id`。请妥善保存，因为将问卷添加到工作流时，需要将其用作 `questionnaire_uuid`。


## OpenAPI

````yaml zh/openapi-25.json POST /v3/questionnaires/
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/:
    post:
      tags:
        - Questionnaires
      summary: 创建问卷
      description: 创建简单的线性问卷。按显示顺序发送 `form_elements`；分支和可重复组需要在控制台中配置。默认为 `published` v1。
      operationId: create_questionnaire
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SimpleQuestionnaireRequest'
            examples:
              Simple:
                summary: 基础问卷
                value:
                  title: Customer Onboarding
                  description: Additional information needed for verification
                  default_language: en
                  languages:
                    - en
                  is_active: true
                  form_elements:
                    - id: occupation
                      element_type: short_text
                      label:
                        en: What is your occupation?
                      is_required: true
                      placeholder:
                        en: Software engineer
                    - id: source_of_funds
                      element_type: multiple_choice
                      label:
                        en: Source of funds
                      is_required: true
                      options:
                        - value: employment
                          label:
                            en: Employment
                        - value: business
                          label:
                            en: Business
                        - value: investments
                          label:
                            en: Investments
                        - value: other
                          label:
                            en: Other
      responses:
        '201':
          description: 问卷已创建。响应包含 `questionnaire_id` — 请保存该 ID，以便在工作流或将来的更新/删除调用中引用此问卷。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/QuestionnaireDetail'
              examples:
                Created:
                  value:
                    questionnaire_id: 11111111-2222-3333-4444-555555555555
                    title: Customer Onboarding
                    description: Additional information needed for verification
                    languages:
                      - en
                    default_language: en
                    is_active: true
                    is_simple_questionnaire: true
                    graph:
                      start_node: occupation
                      nodes:
                        occupation:
                          element_type: SHORT_TEXT
                          is_required: true
                          title:
                            en: What is your occupation?
                          next: source_of_funds
                        source_of_funds:
                          element_type: MULTIPLE_CHOICE
                          is_required: true
                          title:
                            en: Source of funds
                          choices:
                            - value: employment
                              label:
                                en: Employment
                            - value: business
                              label:
                                en: Business
                          next: null
                    sections: []
                    questionnaire_group_id: 11111111-2222-3333-4444-555555555555
                    version: 1
                    status: published
                    published_at: '2026-04-23T10:00:00Z'
                    is_editable: false
        '400':
          description: >-
            验证错误。常见原因：未知的 `element_type`、可翻译字段缺少 `languages` 之一的翻译、`languages`
            缺少 `en`、`default_language` 不在 `languages` 中、选项缺少 `label`、包含
            `branches`/`required_if`/`repeatable_config` 的问题（此 endpoint
            不支持），或发送了原始 `graph` 而不是 `form_elements`。响应体是以字段名为键的 DRF 验证错误。
          content:
            application/json:
              examples:
                Graph not accepted:
                  value:
                    graph: >-
                      The v3 questionnaire API only accepts simple
                      `form_elements`, not `graph`.
                Missing label:
                  value:
                    form_elements:
                      - label:
                          - This field is required.
        '403':
          description: API 密钥缺失、格式错误、已过期或作用域属于其他应用。
          content:
            application/json:
              examples:
                Invalid token:
                  value:
                    detail: You do not have permission to perform this action.
        '415':
          description: '不支持的媒体类型。请设置 `Content-Type: application/json` 并发送 JSON 请求体。'
        '429':
          description: 超出速率限制。请使用指数退避重试。
        '500':
          description: 创建问卷时发生意外服务器错误。可安全重试。
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: curl
          label: cURL
          source: |-
            curl -X POST 'https://verification.didit.me/v3/questionnaires/' \
              -H 'x-api-key: YOUR_API_KEY' \
              -H 'Content-Type: application/json' \
              -d '{
                "title": "Customer Onboarding",
                "default_language": "en",
                "languages": ["en"],
                "form_elements": [
                  {
                    "id": "occupation",
                    "element_type": "short_text",
                    "label": {"en": "What is your occupation?"},
                    "is_required": true
                  }
                ]
              }'
        - lang: python
          label: Python
          source: |-
            from didit import Didit

            # Reads DIDIT_API_KEY.
            client = Didit()

            result = client.questionnaires.create(
                title="Customer Onboarding",
                description="Additional information needed for verification",
                languages=["en"],
                default_language="en",
                is_active=True,
                form_elements=[{
                    "id": "occupation",
                    "element_type": "short_text",
                    "label": {"en": "What is your occupation?"},
                    "placeholder": {"en": "Software engineer"},
                    "is_required": True,
                }, {
                    "id": "source_of_funds",
                    "element_type": "multiple_choice",
                    "label": {"en": "Source of funds"},
                    "is_required": True,
                    "options": [{
                        "value": "employment",
                        "label": {"en": "Employment"},
                    }, {
                        "value": "business",
                        "label": {"en": "Business"},
                    }, {
                        "value": "investments",
                        "label": {"en": "Investments"},
                    }, {
                        "value": "other",
                        "label": {"en": "Other"},
                    }],
                }],
            )
            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.create({
              title: "Customer Onboarding",
              description: "Additional information needed for verification",
              languages: ["en"],
              default_language: "en",
              is_active: true,
              form_elements: [{
                id: "occupation",
                element_type: "short_text",
                label: { en: "What is your occupation?" },
                placeholder: { en: "Software engineer" },
                is_required: true,
              }, {
                id: "source_of_funds",
                element_type: "multiple_choice",
                label: { en: "Source of funds" },
                is_required: true,
                options: [{
                  value: "employment",
                  label: { en: "Employment" },
                }, {
                  value: "business",
                  label: { en: "Business" },
                }, {
                  value: "investments",
                  label: { en: "Investments" },
                }, {
                  value: "other",
                  label: { en: "Other" },
                }],
              }],
            });
            console.log(result);
        - lang: go
          label: Go
          source: "ctx := context.Background()\n// Reads DIDIT_API_KEY.\nclient := didit.NewClient()\n\nresult, err := client.Questionnaires.Create(ctx, didit.SimpleQuestionnaireRequest{\n\tTitle:           \"Customer Onboarding\",\n\tDescription:     didit.String(\"Additional information needed for verification\"),\n\tLanguages:       []string{\"en\"},\n\tDefaultLanguage: didit.String(\"en\"),\n\tIsActive:        didit.Bool(true),\n\tFormElements: []didit.SimpleQuestionnaireElement{{\n\t\tID:          didit.String(\"occupation\"),\n\t\tElementType: \"short_text\",\n\t\tLabel:       map[string]string{\"en\": \"What is your occupation?\"},\n\t\tPlaceholder: didit.Some(map[string]string{\"en\": \"Software engineer\"}),\n\t\tIsRequired:  didit.Bool(true),\n\t}, {\n\t\tID:          didit.String(\"source_of_funds\"),\n\t\tElementType: \"multiple_choice\",\n\t\tLabel:       map[string]string{\"en\": \"Source of funds\"},\n\t\tIsRequired:  didit.Bool(true),\n\t\tOptions: didit.Some([]didit.SimpleQuestionnaireElementOptions{{\n\t\t\tValue: didit.String(\"employment\"),\n\t\t\tLabel: map[string]string{\"en\": \"Employment\"},\n\t\t}, {\n\t\t\tValue: didit.String(\"business\"),\n\t\t\tLabel: map[string]string{\"en\": \"Business\"},\n\t\t}, {\n\t\t\tValue: didit.String(\"investments\"),\n\t\t\tLabel: map[string]string{\"en\": \"Investments\"},\n\t\t}, {\n\t\t\tValue: didit.String(\"other\"),\n\t\t\tLabel: map[string]string{\"en\": \"Other\"},\n\t\t}}),\n\t}},\n})\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"%+v\\n\", result)"
        - lang: java
          label: Java
          source: >-
            import java.util.List;

            import java.util.Map;

            import me.didit.Didit;

            import me.didit.types.SimpleQuestionnaireElement;

            import me.didit.types.SimpleQuestionnaireRequest;


            // Reads DIDIT_API_KEY.

            Didit client = new Didit();


            var result =
            client.questionnaires().create(SimpleQuestionnaireRequest.builder()
                    .title("Customer Onboarding")
                    .description("Additional information needed for verification")
                    .languages(List.of("en"))
                    .defaultLanguage("en")
                    .isActive(true)
                    .formElements(List.of(
                            SimpleQuestionnaireElement.builder()
                                    .id("occupation")
                                    .elementType(SimpleQuestionnaireElement.ElementType.of("short_text"))
                                    .label(Map.of("en", "What is your occupation?"))
                                    .placeholder(Map.of("en", "Software engineer"))
                                    .isRequired(true)
                                    .build(),
                            SimpleQuestionnaireElement.builder()
                                    .id("source_of_funds")
                                    .elementType(SimpleQuestionnaireElement.ElementType.of("multiple_choice"))
                                    .label(Map.of("en", "Source of funds"))
                                    .isRequired(true)
                                    .options(List.of(
                                            SimpleQuestionnaireElement.Options.builder()
                                                    .value("employment")
                                                    .label(Map.of("en", "Employment"))
                                                    .build(),
                                            SimpleQuestionnaireElement.Options.builder()
                                                    .value("business")
                                                    .label(Map.of("en", "Business"))
                                                    .build(),
                                            SimpleQuestionnaireElement.Options.builder()
                                                    .value("investments")
                                                    .label(Map.of("en", "Investments"))
                                                    .build(),
                                            SimpleQuestionnaireElement.Options.builder()
                                                    .value("other")
                                                    .label(Map.of("en", "Other"))
                                                    .build()))
                                    .build()))
                    .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->create([
                'title' => 'Customer Onboarding',
                'description' => 'Additional information needed for verification',
                'languages' => ['en'],
                'default_language' => 'en',
                'is_active' => true,
                'form_elements' => [[
                    'id' => 'occupation',
                    'element_type' => 'short_text',
                    'label' => ['en' => 'What is your occupation?'],
                    'placeholder' => ['en' => 'Software engineer'],
                    'is_required' => true,
                ], [
                    'id' => 'source_of_funds',
                    'element_type' => 'multiple_choice',
                    'label' => ['en' => 'Source of funds'],
                    'is_required' => true,
                    'options' => [[
                        'value' => 'employment',
                        'label' => ['en' => 'Employment'],
                    ], [
                        'value' => 'business',
                        'label' => ['en' => 'Business'],
                    ], [
                        'value' => 'investments',
                        'label' => ['en' => 'Investments'],
                    ], [
                        'value' => 'other',
                        'label' => ['en' => 'Other'],
                    ]],
                ]],
            ]);
            print_r($result->toArray());
        - lang: ruby
          label: Ruby
          source: |-
            require "didit"

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

            result = didit.questionnaires.create(
              title: "Customer Onboarding",
              description: "Additional information needed for verification",
              languages: ["en"],
              default_language: "en",
              is_active: true,
              form_elements: [{
                id: "occupation",
                element_type: "short_text",
                label: { en: "What is your occupation?" },
                placeholder: { en: "Software engineer" },
                is_required: true,
              }, {
                id: "source_of_funds",
                element_type: "multiple_choice",
                label: { en: "Source of funds" },
                is_required: true,
                options: [{
                  value: "employment",
                  label: { en: "Employment" },
                }, {
                  value: "business",
                  label: { en: "Business" },
                }, {
                  value: "investments",
                  label: { en: "Investments" },
                }, {
                  value: "other",
                  label: { en: "Other" },
                }],
              }]
            )
            puts result.to_h
        - lang: csharp
          label: .NET
          source: >-
            using System;

            using System.Collections.Generic;

            using System.Text.Json;

            using Didit;


            // Reads DIDIT_API_KEY.

            using var client = new DiditClient();


            var result = await client.Questionnaires.CreateAsync(new
            SimpleQuestionnaireRequest

            {
                Title = "Customer Onboarding",
                Description = "Additional information needed for verification",
                Languages = new string[] { "en" },
                DefaultLanguage = "en",
                IsActive = true,
                FormElements = new SimpleQuestionnaireElement[]
                {
                    new()
                    {
                        Id = "occupation",
                        ElementType = "short_text",
                        Label = new Dictionary<string, string> { ["en"] = "What is your occupation?" },
                        Placeholder = new Dictionary<string, string> { ["en"] = "Software engineer" },
                        IsRequired = true,
                    },
                    new()
                    {
                        Id = "source_of_funds",
                        ElementType = "multiple_choice",
                        Label = new Dictionary<string, string> { ["en"] = "Source of funds" },
                        IsRequired = true,
                        Options = new SimpleQuestionnaireElementOptions[]
                        {
                            new()
                            {
                                Value = "employment",
                                Label = new Dictionary<string, string> { ["en"] = "Employment" },
                            },
                            new()
                            {
                                Value = "business",
                                Label = new Dictionary<string, string> { ["en"] = "Business" },
                            },
                            new()
                            {
                                Value = "investments",
                                Label = new Dictionary<string, string> { ["en"] = "Investments" },
                            },
                            new()
                            {
                                Value = "other",
                                Label = new Dictionary<string, string> { ["en"] = "Other" },
                            },
                        },
                    },
                },
            });

            Console.WriteLine(JsonSerializer.Serialize(result));
components:
  schemas:
    SimpleQuestionnaireRequest:
      type: object
      description: 创建简单的线性问卷。API 会在内部将 `form_elements` 转换为内部问卷图谱。
      required:
        - title
        - languages
        - form_elements
      properties:
        title:
          type: string
          description: 问卷的内部名称。
        description:
          type: string
          nullable: true
        languages:
          type: array
          description: 每个标签中包含的语言。必须包含 `en`。
          items:
            type: string
          example:
            - en
        default_language:
          type: string
          description: 默认语言。必须包含在 `languages` 中。
          example: en
        is_active:
          type: boolean
          default: true
        status:
          type: string
          enum:
            - draft
            - published
          description: 省略此字段可创建已发布且可用于工作流的问卷。
        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.