Knowledge base erişimini paylaş
Kişiler ve workspace API anahtarları için Knowledge base erişimini verin, değiştirin veya iptal edin
Mevcut bir Knowledge base üzerinde erişim verir, değiştirir veya iptal eder. Hedefler kişiler ve workspace API anahtarlarıdır. Gruplar uygulama içi Share Knowledge bases with the API akışında kalır.
Başlamadan önce
- API key scope:
KNOWLEDGE_FOLDER_APIkapsamına sahip bir API anahtarı gerekir. API anahtarının kendisinin Knowledge base üzerinde Editor rolü olmalıdır. Kurulum için Share Knowledge bases with the API sayfasına bakın. - Knowledge bases: Knowledge Folder API, Library'de Knowledge base olarak görünen kaynakları yönetir.
Base URL
https://api.ajan.ioDedicated deployments Tüm isteklerde
api.ajan.com'u/api/publicile değiştirin.
Roles
| API value | Library label | Access |
|---|---|---|
USER | Viewer | Dosyaları arama ve getirme |
EDITOR | Editor | Yükleme, güncelleme, silme, erişim paylaşma ve yeniden adlandırma |
Yalnızca Viewer yetkisine sahip bir anahtar (Knowledge base üzerinden yalnızca API araması olan anahtar dahil) bu endpoint'leri çağıramaz.
Editor workspace anahtarı, anahtar sahibi workspace admin olmasa bile diğer uygun workspace anahtarlarına yetki verebilir. Uygulama içi Share diyaloğu API anahtarlarını hâlâ yalnızca workspace admin'lerine listeler.
Grant access
POST /knowledge/{folderId}/access
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
folderId | string | Yes | Knowledge base ID'si |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
targetIds | string\[] | Yes | Yetki verilecek kullanıcı ID'leri ve workspace API anahtarı ID'leri. Minimum: 1. Maksimum: 100. |
role | string | Yes | USER veya EDITOR |
Tüm ID'ler bir insan workspace üyesine veya uygun bir workspace API anahtarına çözülmelidir. Group ID'leri kabul edilmez. Personal API key'ler uygun değildir. Herhangi bir ID eksik veya uygun değilse istek başarısız olur ve hiçbir yetki yazılmaz.
Grant with cURL
curl -X POST "https://api.ajan.io/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.ajan.io/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 veya API_KEY |
targetId | string | Yes | Kişi veya workspace API anahtarı ID'si |
role | string | Yes | USER veya EDITOR |
Knowledge base sahibinin erişimini değiştiremezsiniz. Önce Library'de sahipliği yeniden atayın. Hedefin henüz yetkisi yoksa bu istek bir yetki oluşturur.
curl -X PATCH "https://api.ajan.io/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 veya API_KEY |
targetId | string | Yes | Kişi veya workspace API anahtarı ID'si |
Knowledge base sahibinin erişimini iptal edemezsiniz.
curl -X DELETE "https://api.ajan.io/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 | Geçersiz gövde, uygun olmayan paylaşım hedefi veya sahip erişimi değişikliği |
401 | Geçersiz veya eksik API anahtarı |
403 | Eksik KNOWLEDGE_FOLDER_API kapsamı veya anahtar bu Knowledge base'de Editor değil |
404 | Knowledge base veya erişim hedefi bulunamadı |
429 | Rate limit aşıldı |
500 | Beklenmeyen sunucu hatası |
ajan, API anahtarınızı korumak ve uygulamalarınızın güvenliğini sağlamak için tarayıcı kaynaklı istekleri bilinçli olarak engeller. Daha fazla bilgi için API Key Best Practices kılavuzuna bakın.
OpenAPI
openapi: 3.0.0
info:
title: ajan API
version: 3.0.0
servers:
- url: https://api.ajan.io
description: Production
security:
- bearerAuth: []
paths:
/knowledge/{folderId}/access:
post:
summary: Grant Knowledge base access to people or workspace API keys
parameters:
- name: folderId
in: path
required: true
description: The ID of the knowledge folder
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- targetIds
- role
properties:
targetIds:
type: array
items:
type: string
format: uuid
minItems: 1
maxItems: 100
role:
type: string
enum:
- USER
- EDITOR
responses:
'200':
description: Access granted successfully
security:
- bearerAuth: []
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: API Key
description: API key as Bearer token. Format "Bearer YOUR_API_KEY"