Grant Knowledge base access to people or workspace API keys
curl --request POST \
--url https://api.langdock.com/knowledge/{folderId}/access \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"targetIds": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
]
}
'import requests
url = "https://api.langdock.com/knowledge/{folderId}/access"
payload = { "targetIds": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({targetIds: ['3c90c3cc-0d44-4b50-8888-8dd25736052a']})
};
fetch('https://api.langdock.com/knowledge/{folderId}/access', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.langdock.com/knowledge/{folderId}/access",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'targetIds' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.langdock.com/knowledge/{folderId}/access"
payload := strings.NewReader("{\n \"targetIds\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\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))
}HttpResponse<String> response = Unirest.post("https://api.langdock.com/knowledge/{folderId}/access")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"targetIds\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/knowledge/{folderId}/access")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"targetIds\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}"
response = http.request(request)
puts response.read_bodyKnowledge Folder API
Share Knowledge base access
Grant, change, or revoke Knowledge base access for people and workspace API keys
POST
/
knowledge
/
{folderId}
/
access
Grant Knowledge base access to people or workspace API keys
curl --request POST \
--url https://api.langdock.com/knowledge/{folderId}/access \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"targetIds": [
"3c90c3cc-0d44-4b50-8888-8dd25736052a"
]
}
'import requests
url = "https://api.langdock.com/knowledge/{folderId}/access"
payload = { "targetIds": ["3c90c3cc-0d44-4b50-8888-8dd25736052a"] }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({targetIds: ['3c90c3cc-0d44-4b50-8888-8dd25736052a']})
};
fetch('https://api.langdock.com/knowledge/{folderId}/access', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.langdock.com/knowledge/{folderId}/access",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'targetIds' => [
'3c90c3cc-0d44-4b50-8888-8dd25736052a'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.langdock.com/knowledge/{folderId}/access"
payload := strings.NewReader("{\n \"targetIds\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\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))
}HttpResponse<String> response = Unirest.post("https://api.langdock.com/knowledge/{folderId}/access")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"targetIds\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.langdock.com/knowledge/{folderId}/access")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"targetIds\": [\n \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n ]\n}"
response = http.request(request)
puts response.read_bodyGrants, changes, or revokes access on an existing Knowledge base. Targets are people and workspace API keys. Groups stay on the in-app Share Knowledge bases with the API flow.
A Viewer-only key, including a key that only has API search through the Knowledge base, cannot call these endpoints.
An Editor workspace key can grant other qualifying workspace keys even if the key owner is not a workspace admin. The in-app Share dialog still lists API keys only for workspace admins.
All IDs must resolve to a human workspace member or a qualifying workspace API key. Group IDs are not accepted. Personal API keys are not eligible. If any ID is missing or ineligible, the request fails and no grants are written.
You cannot change the Knowledge base owner’s access. Reassign ownership in the Library first. If the target has no grant yet, this request creates one.
You cannot revoke the Knowledge base owner’s access.
Before You Start
- API key scope: Requires an API key with the
KNOWLEDGE_FOLDER_APIscope. The API key itself needs the Editor role on the Knowledge base. See Share Knowledge bases with the API for setup instructions. - Knowledge bases: The Knowledge Folder API manages resources that appear as Knowledge bases in the Library.
Base URL
https://api.langdock.com
Dedicated deploymentsReplace
api.langdock.com with <your-deployment-url>/api/public in all requests.Roles
| API value | Library label | Access |
|---|---|---|
USER | Viewer | Search and retrieve files |
EDITOR | Editor | Upload, update, delete, share access, and rename |
Grant access
POST /knowledge/{folderId}/access
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
folderId | string | Yes | The ID of the Knowledge base |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
targetIds | string[] | Yes | User IDs and workspace API key IDs to grant. Minimum: 1. Maximum: 100. |
role | string | Yes | USER or EDITOR |
Grant with cURL
curl -X POST "https://api.langdock.com/knowledge/{folderId}/access" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"targetIds": [
"7c9e6679-7425-40de-944b-e07fc1f90ae7",
"550e8400-e29b-41d4-a716-446655440000"
],
"role": "EDITOR"
}'
Grant with JavaScript
const axios = require("axios");
async function grantAccess(folderId, targetIds, role) {
const response = await axios.post(
`https://api.langdock.com/knowledge/${folderId}/access`,
{ targetIds, role },
{
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
}
);
return response.data;
}
const result = await grantAccess(
"3fa85f64-5717-4562-b3fc-2c963f66afa6",
["7c9e6679-7425-40de-944b-e07fc1f90ae7"],
"EDITOR"
);
console.log(result.result.granted);
Success Response (200 OK)
{
"status": "success",
"result": {
"granted": [
{
"type": "USER",
"targetId": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"role": "EDITOR"
},
{
"type": "API_KEY",
"targetId": "550e8400-e29b-41d4-a716-446655440000",
"role": "EDITOR"
}
]
}
}
Change a role
PATCH /knowledge/{folderId}/access
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | USER or API_KEY |
targetId | string | Yes | The person or workspace API key ID |
role | string | Yes | USER or EDITOR |
curl -X PATCH "https://api.langdock.com/knowledge/{folderId}/access" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "API_KEY",
"targetId": "550e8400-e29b-41d4-a716-446655440000",
"role": "USER"
}'
{
"status": "success"
}
Revoke access
DELETE /knowledge/{folderId}/access
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | USER or API_KEY |
targetId | string | Yes | The person or workspace API key ID |
curl -X DELETE "https://api.langdock.com/knowledge/{folderId}/access" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"type": "API_KEY",
"targetId": "550e8400-e29b-41d4-a716-446655440000"
}'
{
"status": "success"
}
Error Handling
| Status | Meaning |
|---|---|
400 | Invalid body, ineligible share target, or owner access change |
401 | Invalid or missing API key |
403 | Missing KNOWLEDGE_FOLDER_API scope, or the key is not Editor on this Knowledge base |
404 | Knowledge base or access target not found |
429 | Rate limit exceeded |
500 | Unexpected server error |
Langdock intentionally blocks browser-origin requests to protect your API key and ensure your applications remain secure. For more information, please see our guide on API Key Best Practices.
Authorizations
API key as Bearer token. Format "Bearer YOUR_API_KEY"
Path Parameters
The ID of the knowledge folder
Body
application/json
Response
200
Access granted successfully
Was this page helpful?