Skip to content

创建表单

注意

表单相关接口目前处于 alpha 阶段,接口可能会随时调整,请慎重使用。

创建金山文档表单

基本信息

请求方法:POST

请求路径:/api/v1/openapi/personal/forms

请求主机:developer.kdocs.cn

限流频次

应用类型限额
测试应用
500 次/天
正式应用
100,000 次/天

权限范围

权限值显示名称权限说明
create_form
创建表单
创建表单

Path 参数

参数必须类型说明
form_id
string
表单 id

Query 参数

参数必须类型说明
access_token
string

Body 参数

参数必须类型说明
title
string
表单标题
subtitle
string
表单副标题
+
config
formConfig {}
表单设置
hidden
boolean
是否在表单列表隐藏当前创建的表单(投票类型的表单传 true
+
answer_items
answerItems {}
表单结束语设置
+
questions
questions {}
表单题目
+
questions_sections
questionSections {}
表单题目

提示

questions 为一个 map<string, question>key 为题目 ID,value 为题目内容。

提示

question_sections 为一个对象数组,用来控制表单的展现形式的,尤其注意可以用来控制表单中题目的展示顺序。可以将所有要显示的题目按照顺序,放到一个 question_sections 内部。以下为一个示例:

{
    // 表单内的其它数据先省略,其它字段省略
    "question_sections": [
        {
            "id": "question_section_id",
            "questions": [
                {
                    "qid": "question_id_1",
                },
                {
                    "qid": "question_id_2",
                }
                // 将所有要显示的题目,delete = false 的,都放到这一个元素内
            ]
        }
    ]
}

开放平台提供的题目类型及格式定义如下:

提示

questions 为一个 map<string, question>key 为题目 ID,value 为题目内容。

此处仅列举 questionvalue 部分

不同题型通过 type 字段来标识

填空题类

填空类题目包含如下类型 type

  • input单行填空题-单行填空 IMAGE

  • multiInput 多行填空题-多行填空 IMAGE

  • floatInput 数字填空题-数字 IMAGE

  • telphone 填空题-手机号手机号 IMAGE

  • star 评分题 IMAGE

  • date 填空题-日期日期 IMAGE

  • time 时间填空题-时间 IMAGE

  • signatures 填空题-电子签名电子签名 IMAGE

  • idcard:填空题-身份证号 IMAGE

  • email邮箱填空题-邮箱 IMAGE

  • scanCode 填空题-扫码输入扫码输入 IMAGE

  • multiStepInput 多段填空___第二空___ IMAGE

  • address填空题-地址地址 IMAGE

参数格式:

参数必须类型说明
title
string
题目标题
type
string
题目类型,示例: input 填空题
need
boolean
是否必答
hidden
boolean
是否隐藏

示例:

{
    "questions": {
        "3t56gf": {
            "title": "填空题-单行填空",
            "type": "input",
            "need": true,
            "hidden": false,
            "delete": false
        }
    }
}

选择题类

  • select 选择题-单选题 IMAGE

  • doubleSelect 多选选择题 IMAGE

  • pullSelect 选择题-下拉题子问题 IMAGE

  • multiSelect 选择题-多段选择 IMAGE

参数格式:

参数必须类型说明
title
string
题目标题
type
string
题目类型,示例: input 填空题
need
boolean
是否必答
hidden
boolean
是否隐藏
+
selects
selects[]
选项列表

请求示例:

{
    "questions": {
        "2agiq4": {
            "title": "选择题-多选题",
            "type": "doubleSelect",
            "need": false,
            "hidden": false,
            "delete": false,
            "selects": [
                {
                    "itemId": "k17j6v",
                    "text": "11"
                },
                {
                    "itemId": "i4ijyw",
                    "text": "22"
                }
            ]
        }
    }
}

附件类

  • file 上传单个附件 IMAGE

  • multiFile 上传多份附件 IMAGE

  • newImage 上传单张图片 IMAGE

  • newMultiImage 上传多张图片 IMAGE

参数格式:

参数必须类型说明
title
string
题目标题
type
string
题目类型,示例: input 填空题
need
boolean
是否必答
hidden
boolean
是否隐藏
fileSizeLimit
integer
附件大小限制
fileAcceptType
string[]
附件类型约束,示例:["word", "image"]
+
subItems
subItems[]
附件子项列表

请求示例:

{
    "questions": {
        "7nfwow": {
            "title": "图片题-单张",
            "type": "newImage",
            "need": false,
            "delete": false,
            "subItems": [
                {
                    "itemId": "la0sol",
                    "sort": 1,
                    "text": "图片1"
                }
            ],
            "fileAcceptType": null,
            "fileSizeLimit": 100
        }
    }
}

量表题类

  • scale 量表题 IMAGE

  • matrixScale 矩阵量表题 IMAGE

参数格式:

参数必须类型说明
title
string
题目标题
type
string
题目类型,示例: input 填空题
need
boolean
是否必答
hidden
boolean
是否隐藏
+
subItems
scaleSubItems[]
量表选项列表

请求示例:

{
    "questions": {
        "v45ovc": {
            "title": "矩阵量表题",
            "type": "matrixScale",
            "need": false,
            "delete": false,
            "subItems": [
                {
                    "itemId": "fapyqz",
                    "sort": 0,
                    "text": "子标题1",
                    "scaleSelects": [
                        {
                            "itemId": "z7978q",
                            "text": "1",
                        },
                        {
                            "itemId": "p32a9g",
                            "text": "2",
                        },
                        {
                            "itemId": "fxa687",
                            "text": "3",
                        },
                        {
                            "itemId": "1g1m8d",
                            "text": "4",
                        },
                        {
                            "itemId": "8yopc0",
                            "text": "5",
                        }
                    ],
                    "checkStatus": 0
                },
                {
                    "itemId": "i7vcug",
                    "sort": 1,
                    "text": "子标题2",
                    "scaleSelects": [
                        {
                            "itemId": "p77jax",
                            "text": "1",
                        },
                        {
                            "itemId": "svak5x",
                            "text": "2",
                        },
                        {
                            "itemId": "silc52",
                            "text": "3",
                        },
                        {
                            "itemId": "49ig0h",
                            "text": "4",
                        },
                        {
                            "itemId": "zzt2jw",
                            "text": "5",
                        }
                    ],
                    "checkStatus": 0
                }
            ]
        }
    }
}

返回参数

参数必须类型说明
code
integer
错误码
+
data
data {}
响应数据

示例

请求示例

curl --request POST \
	--url 'https://developer.kdocs.cn/api/v1/openapi/personal/forms?access_token=kvqxrspxjctdojjqdildjhonzwusaquc' \
	--header 'Content-Type: application/json' \
	--data '{"title":"interaction_vote","config":{"varied_config":{"vote_show_time":"","is_vote":true,"is_not_write_excel":true,"information_fill_notify":false},"check_login":false,"check_once":false,"can_secret_vote":false,"expire":0},"hidden":false,"questions":{"1855622480":{"id":"1855622480","title":"123","type":"select","selects":[{"itemId":"1","text":"1"},{"itemId":"2","text":"2"}],"need":true,"hidden":false}},"answer_items":{"closing_remark_text":""},"subtitle":""}'
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"title\":\"interaction_vote\",\"config\":{\"varied_config\":{\"vote_show_time\":\"\",\"is_vote\":true,\"is_not_write_excel\":true,\"information_fill_notify\":false},\"check_login\":false,\"check_once\":false,\"can_secret_vote\":false,\"expire\":0},\"hidden\":false,\"questions\":{\"1855622480\":{\"id\":\"1855622480\",\"title\":\"123\",\"type\":\"select\",\"selects\":[{\"itemId\":\"1\",\"text\":\"1\"},{\"itemId\":\"2\",\"text\":\"2\"}],\"need\":true,\"hidden\":false}},\"answer_items\":{\"closing_remark_text\":\"\"},\"subtitle\":\"\"}");
Request request = new Request.Builder()
	.url("https://developer.kdocs.cn/api/v1/openapi/personal/forms?access_token=kvqxrspxjctdojjqdildjhonzwusaquc")
	.post(body)
	.addHeader("Content-Type", "application/json")
	.build();

Response response = client.newCall(request).execute();
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io/ioutil"
)

func main() {

	url := "https://developer.kdocs.cn/api/v1/openapi/personal/forms?access_token=kvqxrspxjctdojjqdildjhonzwusaquc"

	payload := strings.NewReader("{\"title\":\"interaction_vote\",\"config\":{\"varied_config\":{\"vote_show_time\":\"\",\"is_vote\":true,\"is_not_write_excel\":true,\"information_fill_notify\":false},\"check_login\":false,\"check_once\":false,\"can_secret_vote\":false,\"expire\":0},\"hidden\":false,\"questions\":{\"1855622480\":{\"id\":\"1855622480\",\"title\":\"123\",\"type\":\"select\",\"selects\":[{\"itemId\":\"1\",\"text\":\"1\"},{\"itemId\":\"2\",\"text\":\"2\"}],\"need\":true,\"hidden\":false}},\"answer_items\":{\"closing_remark_text\":\"\"},\"subtitle\":\"\"}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := ioutil.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
import http.client

conn = http.client.HTTPSConnection("developer.kdocs.cn")

payload = "{\"title\":\"interaction_vote\",\"config\":{\"varied_config\":{\"vote_show_time\":\"\",\"is_vote\":true,\"is_not_write_excel\":true,\"information_fill_notify\":false},\"check_login\":false,\"check_once\":false,\"can_secret_vote\":false,\"expire\":0},\"hidden\":false,\"questions\":{\"1855622480\":{\"id\":\"1855622480\",\"title\":\"123\",\"type\":\"select\",\"selects\":[{\"itemId\":\"1\",\"text\":\"1\"},{\"itemId\":\"2\",\"text\":\"2\"}],\"need\":true,\"hidden\":false}},\"answer_items\":{\"closing_remark_text\":\"\"},\"subtitle\":\"\"}"

headers = { 'Content-Type': "application/json" }

conn.request("POST", "/api/v1/openapi/personal/forms?access_token=kvqxrspxjctdojjqdildjhonzwusaquc", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
<?php

$curl = curl_init();

curl_setopt_array($curl, [
	CURLOPT_URL => "https://developer.kdocs.cn/api/v1/openapi/personal/forms?access_token=kvqxrspxjctdojjqdildjhonzwusaquc",
	CURLOPT_RETURNTRANSFER => true,
	CURLOPT_ENCODING => "",
	CURLOPT_MAXREDIRS => 10,
	CURLOPT_TIMEOUT => 30,
	CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	CURLOPT_CUSTOMREQUEST => "POST",
	CURLOPT_POSTFIELDS => "{\"title\":\"interaction_vote\",\"config\":{\"varied_config\":{\"vote_show_time\":\"\",\"is_vote\":true,\"is_not_write_excel\":true,\"information_fill_notify\":false},\"check_login\":false,\"check_once\":false,\"can_secret_vote\":false,\"expire\":0},\"hidden\":false,\"questions\":{\"1855622480\":{\"id\":\"1855622480\",\"title\":\"123\",\"type\":\"select\",\"selects\":[{\"itemId\":\"1\",\"text\":\"1\"},{\"itemId\":\"2\",\"text\":\"2\"}],\"need\":true,\"hidden\":false}},\"answer_items\":{\"closing_remark_text\":\"\"},\"subtitle\":\"\"}",
	CURLOPT_HTTPHEADER => [
		"Content-Type: application/json"
	],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
	echo "cURL Error #:" . $err;
} else {
	echo $response;
}
const data = JSON.stringify({
	"title": "interaction_vote",
	"config": {
		"varied_config": {
			"vote_show_time": "",
			"is_vote": true,
			"is_not_write_excel": true,
			"information_fill_notify": false
		},
		"check_login": false,
		"check_once": false,
		"can_secret_vote": false,
		"expire": 0
	},
	"hidden": false,
	"questions": {
		"1855622480": {
			"id": "1855622480",
			"title": "123",
			"type": "select",
			"selects": [
				{
					"itemId": "1",
					"text": "1"
				},
				{
					"itemId": "2",
					"text": "2"
				}
			],
			"need": true,
			"hidden": false
		}
	},
	"answer_items": {
		"closing_remark_text": ""
	},
	"subtitle": ""
});

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
	if (this.readyState === this.DONE) {
		console.log(this.responseText);
	}
});

xhr.open("POST", "https://developer.kdocs.cn/api/v1/openapi/personal/forms?access_token=kvqxrspxjctdojjqdildjhonzwusaquc");
xhr.setRequestHeader("Content-Type", "application/json");

xhr.send(data);
const http = require("https");

const options = {
	"method": "POST",
	"hostname": "developer.kdocs.cn",
	"port": null,
	"path": "/api/v1/openapi/personal/forms?access_token=kvqxrspxjctdojjqdildjhonzwusaquc",
	"headers": {
		"Content-Type": "application/json"
	}
};

const req = http.request(options, function (res) {
	const chunks = [];

	res.on("data", function (chunk) {
		chunks.push(chunk);
	});

	res.on("end", function () {
		const body = Buffer.concat(chunks);
		console.log(body.toString());
	});
});

req.write(JSON.stringify({
  title: 'interaction_vote',
  config: {
    varied_config: {
      vote_show_time: '',
      is_vote: true,
      is_not_write_excel: true,
      information_fill_notify: false
    },
    check_login: false,
    check_once: false,
    can_secret_vote: false,
    expire: 0
  },
  hidden: false,
  questions: {
    '1855622480': {
      id: '1855622480',
      title: '123',
      type: 'select',
      selects: [{itemId: '1', text: '1'}, {itemId: '2', text: '2'}],
      need: true,
      hidden: false
    }
  },
  answer_items: {closing_remark_text: ''},
  subtitle: ''
}));
req.end();
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://developer.kdocs.cn/api/v1/openapi/personal/forms?access_token=kvqxrspxjctdojjqdildjhonzwusaquc");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"title\":\"interaction_vote\",\"config\":{\"varied_config\":{\"vote_show_time\":\"\",\"is_vote\":true,\"is_not_write_excel\":true,\"information_fill_notify\":false},\"check_login\":false,\"check_once\":false,\"can_secret_vote\":false,\"expire\":0},\"hidden\":false,\"questions\":{\"1855622480\":{\"id\":\"1855622480\",\"title\":\"123\",\"type\":\"select\",\"selects\":[{\"itemId\":\"1\",\"text\":\"1\"},{\"itemId\":\"2\",\"text\":\"2\"}],\"need\":true,\"hidden\":false}},\"answer_items\":{\"closing_remark_text\":\"\"},\"subtitle\":\"\"}");

CURLcode ret = curl_easy_perform(hnd);
var client = new RestClient("https://developer.kdocs.cn/api/v1/openapi/personal/forms?access_token=kvqxrspxjctdojjqdildjhonzwusaquc");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\"title\":\"interaction_vote\",\"config\":{\"varied_config\":{\"vote_show_time\":\"\",\"is_vote\":true,\"is_not_write_excel\":true,\"information_fill_notify\":false},\"check_login\":false,\"check_once\":false,\"can_secret_vote\":false,\"expire\":0},\"hidden\":false,\"questions\":{\"1855622480\":{\"id\":\"1855622480\",\"title\":\"123\",\"type\":\"select\",\"selects\":[{\"itemId\":\"1\",\"text\":\"1\"},{\"itemId\":\"2\",\"text\":\"2\"}],\"need\":true,\"hidden\":false}},\"answer_items\":{\"closing_remark_text\":\"\"},\"subtitle\":\"\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

返回示例

{
  "code": 0,
  "data": {
    "id": {
      "open_id": "JxdxSDJpnZKRRr0dEKZRuKzClBub7Uz7m1caY_YSxZg",
      "union_id": "-9Yu8Qo2oJirjqhvNofycKzClBub7Uz7m1caY_YSxZg"
    },
    "super_token": "ok"
  }
}

错误码

请参考错误码说明