Create Tag Binding
Bind one or more tags to a knowledge base. A knowledge base can have multiple tags.
1 min read
post/datasets/tags/binding
Request example
curl --request POST \
--url https://api.dify.ai/v1/datasets/tags/binding \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{
"tag_ids": [
"<string>"
],
"target_id": "<string>"
}'import requests
url = "https://api.dify.ai/v1/datasets/tags/binding"
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
}
payload = {
"tag_ids": [
"<string>"
],
"target_id": "<string>"
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)const response = await fetch('https://api.dify.ai/v1/datasets/tags/binding', {
method: 'POST',
headers: {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"tag_ids": [
"<string>"
],
"target_id": "<string>"
})
});
const data = await response.json();
console.log(data);<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://api.dify.ai/v1/datasets/tags/binding',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{
"tag_ids": [
"<string>"
],
"target_id": "<string>"
}',
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/datasets/tags/binding"
payload := strings.NewReader("{\n \"tag_ids\": [\n \"<string>\"\n ],\n \"target_id\": \"<string>\"\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/datasets/tags/binding"))
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("{\n \"tag_ids\": [\n \"<string>\"\n ],\n \"target_id\": \"<string>\"\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/datasets/tags/binding')
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 = '{
"tag_ids": [
"<string>"
],
"target_id": "<string>"
}'
response = http.request(request)
puts response.read_bodyResponse
{
"code": "forbidden",
"message": "The API key is not authorized to access this knowledge base.",
"status": 403
}{
"code": "not_found",
"message": "Dataset not found",
"status": 404
}post/datasets/tags/binding
Authorization
Every request authenticates with an API key: Authorization: Bearer {API_KEY}. App endpoints take an app API key; knowledge endpoints take a knowledge base API key (Get Started).
Keep keys server-side; never embed them in client code. Requests with a missing or invalid key fail with HTTP 401 (unauthorized).
Body
application/jsonIDs of the tags to bind. See List Knowledge Type Tags. Unknown tag IDs are silently ignored.
Items: min 1
Knowledge base to bind the tags to. See List Knowledge Bases.
Responses
Success.