提交人工介入表单
适用于:Chatflow、Workflow。
向暂停中的人工介入表单提交接收人的响应。接受后工作流将恢复;可通过 流式获取工作流事件 跟踪恢复后的运行。需要 Web 应用提交方式。
1 min read
post/form/human_input/{form_token}
Request example
curl --request POST \
--url https://api.dify.ai/v1/form/human_input/{form_token} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"action": "approve",
"inputs": {
"attachment": {
"transfer_method": "local_file",
"type": "image",
"upload_file_id": "3c8fa1b2-7d4e-4f9a-b0c1-d2e3f4a5b6c7"
},
"attachments": [
{
"transfer_method": "local_file",
"type": "document",
"upload_file_id": "1a77f0df-c0e6-461c-987c-e72526f341ee"
},
{
"transfer_method": "remote_url",
"type": "document",
"url": "https://example.com/report.pdf"
}
],
"feedback": "可以发布",
"priority": "high"
},
"user": "abc-123"
}'import requests
url = "https://api.dify.ai/v1/form/human_input/{form_token}"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
}
payload = {
"action": "approve",
"inputs": {
"attachment": {
"transfer_method": "local_file",
"type": "image",
"upload_file_id": "3c8fa1b2-7d4e-4f9a-b0c1-d2e3f4a5b6c7"
},
"attachments": [
{
"transfer_method": "local_file",
"type": "document",
"upload_file_id": "1a77f0df-c0e6-461c-987c-e72526f341ee"
},
{
"transfer_method": "remote_url",
"type": "document",
"url": "https://example.com/report.pdf"
}
],
"feedback": "可以发布",
"priority": "high"
},
"user": "abc-123"
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)const response = await fetch('https://api.dify.ai/v1/form/human_input/{form_token}', {
method: 'POST',
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"action": "approve",
"inputs": {
"attachment": {
"transfer_method": "local_file",
"type": "image",
"upload_file_id": "3c8fa1b2-7d4e-4f9a-b0c1-d2e3f4a5b6c7"
},
"attachments": [
{
"transfer_method": "local_file",
"type": "document",
"upload_file_id": "1a77f0df-c0e6-461c-987c-e72526f341ee"
},
{
"transfer_method": "remote_url",
"type": "document",
"url": "https://example.com/report.pdf"
}
],
"feedback": "可以发布",
"priority": "high"
},
"user": "abc-123"
})
});
const data = await response.json();
console.log(data);<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.dify.ai/v1/form/human_input/{form_token}',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"action": "approve",
"inputs": {
"attachment": {
"transfer_method": "local_file",
"type": "image",
"upload_file_id": "3c8fa1b2-7d4e-4f9a-b0c1-d2e3f4a5b6c7"
},
"attachments": [
{
"transfer_method": "local_file",
"type": "document",
"upload_file_id": "1a77f0df-c0e6-461c-987c-e72526f341ee"
},
{
"transfer_method": "remote_url",
"type": "document",
"url": "https://example.com/report.pdf"
}
],
"feedback": "可以发布",
"priority": "high"
},
"user": "abc-123"
}',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer <token>',
'Content-Type: application/json',
],
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
url := "https://api.dify.ai/v1/form/human_input/{form_token}"
payload := strings.NewReader("{\n \"action\": \"approve\",\n \"inputs\": {\n \"attachment\": {\n \"transfer_method\": \"local_file\",\n \"type\": \"image\",\n \"upload_file_id\": \"3c8fa1b2-7d4e-4f9a-b0c1-d2e3f4a5b6c7\"\n },\n \"attachments\": [\n {\n \"transfer_method\": \"local_file\",\n \"type\": \"document\",\n \"upload_file_id\": \"1a77f0df-c0e6-461c-987c-e72526f341ee\"\n },\n {\n \"transfer_method\": \"remote_url\",\n \"type\": \"document\",\n \"url\": \"https://example.com/report.pdf\"\n }\n ],\n \"feedback\": \"可以发布\",\n \"priority\": \"high\"\n },\n \"user\": \"abc-123\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.dify.ai/v1/form/human_input/{form_token}"))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("{\n \"action\": \"approve\",\n \"inputs\": {\n \"attachment\": {\n \"transfer_method\": \"local_file\",\n \"type\": \"image\",\n \"upload_file_id\": \"3c8fa1b2-7d4e-4f9a-b0c1-d2e3f4a5b6c7\"\n },\n \"attachments\": [\n {\n \"transfer_method\": \"local_file\",\n \"type\": \"document\",\n \"upload_file_id\": \"1a77f0df-c0e6-461c-987c-e72526f341ee\"\n },\n {\n \"transfer_method\": \"remote_url\",\n \"type\": \"document\",\n \"url\": \"https://example.com/report.pdf\"\n }\n ],\n \"feedback\": \"可以发布\",\n \"priority\": \"high\"\n },\n \"user\": \"abc-123\"\n}"))
.build();
HttpResponse<String> response = HttpClient.newHttpClient()
.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());require 'uri'
require 'net/http'
url = URI('https://api.dify.ai/v1/form/human_input/{form_token}')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = url.scheme == 'https'
request = Net::HTTP::Post.new(url)
request['Authorization'] = 'Bearer <token>'
request['Content-Type'] = 'application/json'
request.body = '{
"action": "approve",
"inputs": {
"attachment": {
"transfer_method": "local_file",
"type": "image",
"upload_file_id": "3c8fa1b2-7d4e-4f9a-b0c1-d2e3f4a5b6c7"
},
"attachments": [
{
"transfer_method": "local_file",
"type": "document",
"upload_file_id": "1a77f0df-c0e6-461c-987c-e72526f341ee"
},
{
"transfer_method": "remote_url",
"type": "document",
"url": "https://example.com/report.pdf"
}
],
"feedback": "可以发布",
"priority": "high"
},
"user": "abc-123"
}'
response = http.request(request)
puts response.read_bodyResponse
{}{
"code": "bad_request",
"message": "Form recipient type is invalid",
"status": 400
}{
"code": "invalid_form_data",
"message": "Missing required inputs: feedback",
"status": 400
}{
"code": "not_found",
"message": "Form not found",
"status": 404
}{
"code": "human_input_form_expired",
"message": "This form has expired, form_id=a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"status": 412
}{
"code": "human_input_form_submitted",
"message": "This form has already been submitted by another user, form_id=a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"status": 412
}post/form/human_input/{form_token}
Authorization
Path parameters
暂停表单的访问令牌,由执行工作流或发送对话消息接口在流式返回时发送的
human_input_required 事件提供。Body
application/json按各输入的 output_variable_name 作为键提交的值。段落和下拉选项输入为字符串;file 输入为单个文件映射;file-list 输入为文件映射数组。
文件映射为 {transfer_method: local_file, upload_file_id, type} 或 {transfer_method: remote_url, url, type},其中 type 为该字段 allowed_file_types 中的一种。对于 local_file,upload_file_id 为 上传文件 返回的 id。
在执行、上传和提交各次调用中使用一致的 user。
Responses
application/json
表单提交成功。响应体为空对象。