Outline API 开发指南
【核心概念】API 基础架构
接口设计理念
Outline 提供的 RESTful API 采用资源导向设计,允许开发者通过标准化接口与团队知识库进行交互。您可以通过这些接口实现文档的全生命周期管理,从创建到删除的完整操作流程,以及权限控制、搜索等高级功能。
基础信息
| 项目 | 说明 |
|---|---|
| 基础URL | /api |
| 认证方式 | JWT(JSON Web Token) |
| 请求格式 | JSON |
| 响应格式 | JSON |
| 状态码 | 遵循HTTP标准状态码 |
适用场景
- 第三方集成:将 Outline 知识库与项目管理工具、CRM系统或内部工作流平台集成
- 自动化脚本:批量创建、更新或导出文档
- 自定义前端:构建符合特定团队需求的定制化界面
- 数据分析:提取文档元数据进行知识图谱分析
- 移动应用:开发配套移动客户端
通用响应结构
所有 API 接口返回的响应遵循以下结构:
{
"pagination": {
"offset": 0,
"limit": 20,
"total": 100
},
"data": [],
"policies": {}
}
pagination:分页信息,仅在返回列表数据时包含data:接口返回的具体数据policies:权限信息,描述当前用户对返回资源的操作权限
[!NOTE] 所有需要认证的接口必须在请求头中包含
Authorization: Bearer YOUR_JWT_TOKEN
【操作指南】文档管理核心接口
文档查询与管理
获取文档列表
功能描述:您可以通过此接口获取符合特定条件的文档集合,支持多种筛选和排序方式。
请求规范:
- 接口路径:
POST /api/documents.list - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| sort | string | 排序字段,可选值:createdAt, updatedAt, publishedAt, index, title | 否 | updatedAt |
| direction | string | 排序方向,可选值:ASC, DESC | 否 | DESC |
| userId | string | 创建者ID,用于筛选特定用户创建的文档 | 否 | null |
| collectionId | string | 集合ID,用于筛选特定集合下的文档 | 否 | null |
| backlinkDocumentId | string | 反向链接文档ID,用于筛选引用了指定文档的文档 | 否 | null |
| parentDocumentId | string | 父文档ID,用于筛选特定父文档下的子文档 | 否 | null |
| template | boolean | 是否为模板文档 | 否 | false |
| statusFilter | array | 状态筛选,可选值:published, draft, archived | 否 | ["published", "draft"] |
响应示例:
{
"pagination": {
"offset": 0,
"limit": 20,
"total": 100
},
"data": [
{
"id": "doc_123456",
"title": "API文档使用指南",
"text": "这是一份详细的API文档使用指南...",
"createdAt": "2025-01-15T08:30:00Z",
"updatedAt": "2025-01-20T14:15:00Z",
"publishedAt": "2025-01-16T09:00:00Z",
"collectionId": "col_789",
"parentDocumentId": null,
"createdBy": {
"id": "user_456",
"name": "开发团队"
},
"icon": "file-text",
"color": "#3B82F6",
"isTemplate": false,
"isArchived": false,
"isDeleted": false
}
],
"policies": {
"doc_123456": {
"canRead": true,
"canUpdate": true,
"canDelete": true
}
}
}
代码示例:
Python:
import requests
import json
url = "https://your-outline-instance.com/api/documents.list"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_JWT_TOKEN"
}
data = {
"sort": "updatedAt",
"direction": "DESC",
"collectionId": "col_789"
}
response = requests.post(url, headers=headers, data=json.dumps(data))
result = response.json()
print(result)
JavaScript:
fetch('https://your-outline-instance.com/api/documents.list', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_JWT_TOKEN'
},
body: JSON.stringify({
sort: 'updatedAt',
direction: 'DESC',
collectionId: 'col_789'
})
})
.then(response => response.json())
.then(data => console.log(data));
获取文档详情
功能描述:您可以通过文档ID获取单个文档的详细信息,包括内容、版本历史、评论和附件等。
请求规范:
- 接口路径:
POST /api/documents.info - 认证要求:需要认证或通过共享链接访问
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| id | string | 文档ID | 是 | - |
| shareId | string | 共享链接ID,用于通过共享链接访问文档 | 否 | null |
| apiVersion | number | API版本,可选值:1, 2 | 否 | 2 |
响应示例:
{
"data": {
"document": {
"id": "doc_123456",
"title": "API文档使用指南",
"text": "这是一份详细的API文档使用指南...",
"createdAt": "2025-01-15T08:30:00Z",
"updatedAt": "2025-01-20T14:15:00Z",
"publishedAt": "2025-01-16T09:00:00Z",
"collectionId": "col_789",
"parentDocumentId": null,
"createdBy": {
"id": "user_456",
"name": "开发团队"
},
"icon": "file-text",
"color": "#3B82F6",
"isTemplate": false,
"isArchived": false,
"isDeleted": false,
"revisions": [
{
"id": "rev_987",
"createdAt": "2025-01-20T14:15:00Z",
"createdBy": {
"id": "user_456",
"name": "开发团队"
}
}
],
"comments": [],
"attachments": []
}
},
"policies": {
"canRead": true,
"canUpdate": true,
"canDelete": true
}
}
代码示例:
Python:
import requests
import json
url = "https://your-outline-instance.com/api/documents.info"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_JWT_TOKEN"
}
data = {
"id": "doc_123456"
}
response = requests.post(url, headers=headers, data=json.dumps(data))
result = response.json()
print(result)
JavaScript:
fetch('https://your-outline-instance.com/api/documents.info', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_JWT_TOKEN'
},
body: JSON.stringify({
id: 'doc_123456'
})
})
.then(response => response.json())
.then(data => console.log(data));
文档创建与修改
创建文档
功能描述:您可以通过此接口创建新文档,支持基于模板创建、设置文档属性和初始内容。
请求规范:
- 接口路径:
POST /api/documents.create - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| id | string | 文档ID,可选,不提供则自动生成 | 否 | null |
| title | string | 文档标题 | 是 | - |
| text | string | 文档内容,使用ProseMirror JSON格式 | 否 | "" |
| icon | string | 文档图标 | 否 | "file-text" |
| color | string | 图标颜色,十六进制格式 | 否 | "#000000" |
| publish | boolean | 是否发布 | 否 | true |
| collectionId | string | 所属集合ID | 是 | - |
| parentDocumentId | string | 父文档ID | 否 | null |
| templateId | string | 模板ID,用于基于模板创建文档 | 否 | null |
| createdAt | string | 创建时间,可选,默认为当前时间 | 否 | 当前时间 |
| fullWidth | boolean | 是否全屏显示 | 否 | false |
| template | boolean | 是否为模板文档 | 否 | false |
响应示例:
{
"data": {
"id": "doc_123456",
"title": "新API文档",
"text": "这是一篇新创建的API文档...",
"createdAt": "2025-03-10T10:00:00Z",
"updatedAt": "2025-03-10T10:00:00Z",
"publishedAt": "2025-03-10T10:00:00Z",
"collectionId": "col_789",
"parentDocumentId": null,
"createdBy": {
"id": "user_456",
"name": "开发团队"
},
"icon": "file-text",
"color": "#3B82F6",
"isTemplate": false,
"isArchived": false,
"isDeleted": false
},
"policies": {
"canRead": true,
"canUpdate": true,
"canDelete": true
}
}
代码示例:
Python:
import requests
import json
url = "https://your-outline-instance.com/api/documents.create"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_JWT_TOKEN"
}
data = {
"title": "新API文档",
"text": "{\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\",\"content\":[{\"type\":\"text\",\"text\":\"这是一篇新创建的API文档...\"}]}]}",
"collectionId": "col_789",
"publish": True,
"icon": "file-text",
"color": "#3B82F6"
}
response = requests.post(url, headers=headers, data=json.dumps(data))
result = response.json()
print(result)
JavaScript:
fetch('https://your-outline-instance.com/api/documents.create', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_JWT_TOKEN'
},
body: JSON.stringify({
title: '新API文档',
text: JSON.stringify({
type: 'doc',
content: [{
type: 'paragraph',
content: [{
type: 'text',
text: '这是一篇新创建的API文档...'
}]
}]
}),
collectionId: 'col_789',
publish: true,
icon: 'file-text',
color: '#3B82F6'
})
})
.then(response => response.json())
.then(data => console.log(data));
更新文档
功能描述:您可以通过此接口更新现有文档的内容、标题、属性或状态。
请求规范:
- 接口路径:
POST /api/documents.update - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| id | string | 文档ID | 是 | - |
| title | string | 新文档标题 | 否 | 当前标题 |
| text | string | 新文档内容 | 否 | 当前内容 |
| icon | string | 文档图标 | 否 | 当前图标 |
| color | string | 图标颜色 | 否 | 当前颜色 |
| fullWidth | boolean | 是否全屏显示 | 否 | 当前设置 |
| insightsEnabled | boolean | 是否启用洞察功能 | 否 | true |
| publish | boolean | 是否发布 | 否 | 当前状态 |
| templateId | string | 模板ID | 否 | null |
| collectionId | string | 所属集合ID | 否 | 当前集合ID |
| append | boolean | 是否追加内容 | 否 | false |
| done | boolean | 编辑会话是否完成 | 否 | true |
响应示例:
{
"data": {
"id": "doc_123456",
"title": "更新后的API文档",
"updatedAt": "2025-03-10T11:30:00Z"
}
}
代码示例:
Python:
import requests
import json
url = "https://your-outline-instance.com/api/documents.update"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_JWT_TOKEN"
}
data = {
"id": "doc_123456",
"title": "更新后的API文档",
"text": "{\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\",\"content\":[{\"type\":\"text\",\"text\":\"这是更新后的文档内容...\"}]}]}"
}
response = requests.post(url, headers=headers, data=json.dumps(data))
result = response.json()
print(result)
JavaScript:
fetch('https://your-outline-instance.com/api/documents.update', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_JWT_TOKEN'
},
body: JSON.stringify({
id: 'doc_123456',
title: '更新后的API文档',
text: JSON.stringify({
type: 'doc',
content: [{
type: 'paragraph',
content: [{
type: 'text',
text: '这是更新后的文档内容...'
}]
}]
})
})
})
.then(response => response.json())
.then(data => console.log(data));
文档状态管理
删除文档
功能描述:您可以通过此接口删除文档,支持临时删除(放入回收站)或永久删除。
请求规范:
- 接口路径:
POST /api/documents.delete - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| id | string | 文档ID | 是 | - |
| permanent | boolean | 是否永久删除,默认为false(放入回收站) | 否 | false |
响应示例:
{
"data": {
"id": "doc_123456",
"deletedAt": "2025-03-10T14:20:00Z"
}
}
代码示例:
Python:
import requests
import json
url = "https://your-outline-instance.com/api/documents.delete"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_JWT_TOKEN"
}
data = {
"id": "doc_123456",
"permanent": False
}
response = requests.post(url, headers=headers, data=json.dumps(data))
result = response.json()
print(result)
JavaScript:
fetch('https://your-outline-instance.com/api/documents.delete', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_JWT_TOKEN'
},
body: JSON.stringify({
id: 'doc_123456',
permanent: false
})
})
.then(response => response.json())
.then(data => console.log(data));
归档与恢复文档
功能描述:您可以通过这些接口将文档归档或从归档状态恢复,帮助管理文档生命周期。
归档文档请求规范:
- 接口路径:
POST /api/documents.archive - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| id | string | 文档ID | 是 | - |
响应示例:
{
"data": {
"id": "doc_123456",
"archivedAt": "2025-03-10T15:30:00Z"
}
}
恢复文档请求规范:
- 接口路径:
POST /api/documents.restore - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| id | string | 文档ID | 是 | - |
| collectionId | string | 恢复到的集合ID | 否 | 原集合ID |
| revisionId | string | 恢复到的版本ID | 否 | 最新版本 |
响应示例:
{
"data": {
"id": "doc_123456",
"deletedAt": null,
"archivedAt": null
}
}
代码示例:
Python(归档文档):
import requests
import json
url = "https://your-outline-instance.com/api/documents.archive"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_JWT_TOKEN"
}
data = {
"id": "doc_123456"
}
response = requests.post(url, headers=headers, data=json.dumps(data))
result = response.json()
print(result)
JavaScript(恢复文档):
fetch('https://your-outline-instance.com/api/documents.restore', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_JWT_TOKEN'
},
body: JSON.stringify({
id: 'doc_123456',
collectionId: 'col_789'
})
})
.then(response => response.json())
.then(data => console.log(data));
【高级特性】文档操作与权限控制
文档高级操作
复制文档
功能描述:您可以通过此接口复制现有文档,支持递归复制子文档和自定义新文档属性。
请求规范:
- 接口路径:
POST /api/documents.duplicate - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| id | string | 源文档ID | 是 | - |
| title | string | 新文档标题 | 否 | "原标题 (副本)" |
| recursive | boolean | 是否递归复制子文档 | 否 | false |
| publish | boolean | 是否发布新文档 | 否 | false |
| collectionId | string | 新文档所属集合ID | 否 | 源文档集合ID |
| parentDocumentId | string | 新文档父文档ID | 否 | 源文档父文档ID |
响应示例:
{
"data": {
"id": "doc_789012",
"title": "API文档使用指南 (副本)"
}
}
移动文档
功能描述:您可以通过此接口将文档移动到不同的集合或父文档下,并可指定在父文档中的位置。
请求规范:
- 接口路径:
POST /api/documents.move - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| id | string | 文档ID | 是 | - |
| collectionId | string | 目标集合ID | 是 | - |
| parentDocumentId | string | 目标父文档ID | 否 | null |
| index | number | 在父文档中的位置索引 | 否 | 0 |
响应示例:
{
"data": {
"id": "doc_123456",
"collectionId": "col_456",
"parentDocumentId": "doc_789"
}
}
导入与导出文档
功能描述:您可以通过这些接口导入外部文档或导出现有文档为不同格式。
导出文档请求规范:
- 接口路径:
POST /api/documents.export - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| id | string | 文档ID | 是 | - |
响应:响应为文件下载,根据Accept请求头的不同,支持以下格式:
- text/html:HTML格式
- text/markdown:Markdown格式
- application/pdf:PDF格式(仅企业版支持)
导入文档请求规范:
- 接口路径:
POST /api/documents.import - 认证要求:需要认证
- 请求体:multipart/form-data格式,包含要导入的文件
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| publish | boolean | 是否发布导入的文档 | 否 | true |
| collectionId | string | 导入到的集合ID | 是 | - |
| parentDocumentId | string | 导入到的父文档ID | 否 | null |
响应示例:
{
"data": {
"taskId": "task_123",
"status": "processing"
}
}
文档搜索功能
搜索文档标题
功能描述:您可以通过此接口搜索文档标题,支持多种筛选条件。
请求规范:
- 接口路径:
POST /api/documents.search_titles - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| query | string | 搜索关键词 | 是 | - |
| collectionId | string | 集合ID | 否 | null |
| userId | string | 创建者ID | 否 | null |
| dateFilter | string | 日期筛选,可选值:day, week, month, year | 否 | null |
| statusFilter | array | 状态筛选 | 否 | ["published"] |
| snippetMinWords | number | 摘要最小单词数 | 否 | 20 |
| snippetMaxWords | number | 摘要最大单词数 | 否 | 30 |
响应示例:
{
"pagination": {
"offset": 0,
"limit": 20,
"total": 5
},
"data": [
{
"id": "doc_123456",
"title": "API文档使用指南",
"snippet": "这是一份详细的API文档使用指南,包含了所有核心接口的调用方法...",
"updatedAt": "2025-01-20T14:15:00Z",
"collectionId": "col_789"
}
],
"policies": {}
}
搜索文档内容
功能描述:您可以通过此接口搜索文档内容,支持全文搜索和特定文档内搜索。
请求规范:
- 接口路径:
POST /api/documents.search - 认证要求:需要认证或通过共享链接访问
参数说明:除与搜索文档标题接口相同的参数外,增加:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| documentId | string | 文档ID,用于搜索特定文档内的内容 | 否 | null |
| shareId | string | 共享链接ID,用于通过共享链接搜索 | 否 | null |
响应示例:与搜索文档标题接口类似,但data字段会包含匹配的内容摘要。
权限管理
用户与组权限管理
功能描述:您可以通过这些接口管理文档的用户和组权限,控制谁可以查看、编辑或管理文档。
添加用户权限请求规范:
- 接口路径:
POST /api/documents.add_user - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| id | string | 文档ID | 是 | - |
| userId | string | 用户ID | 是 | - |
| permission | string | 权限级别,可选值:read, read_write, admin | 是 | - |
响应示例:
{
"data": {
"documentId": "doc_123456",
"userId": "user_789",
"permission": "read_write"
}
}
添加组权限请求规范:
- 接口路径:
POST /api/documents.add_group - 认证要求:需要认证
参数说明:
| 参数名 | 类型 | 描述 | 是否必填 | 默认值 |
|---|---|---|---|---|
| id | string | 文档ID | 是 | - |
| groupId | string | 组ID | 是 | - |
| permission | string | 权限级别,可选值:read, read_write, admin | 是 | - |
响应示例:
{
"data": {
"documentId": "doc_123456",
"groupId": "group_456",
"permission": "read"
}
}
移除权限接口:
- 移除用户权限:
POST /api/documents.remove_user - 移除组权限:
POST /api/documents.remove_group
【最佳实践】接口调用指南
问题排查指南
常见错误码解析
| 状态码 | 描述 | 可能原因 | 解决方案 |
|---|---|---|---|
| 400 | 请求参数错误 | 请求参数格式错误或缺失必填参数 | 检查请求参数是否符合文档规范 |
| 401 | 未授权 | 未提供令牌或令牌已过期 | 获取新的JWT令牌并在请求头中正确设置 |
| 403 | 权限不足 | 用户没有执行该操作的权限 | 联系文档管理员获取相应权限 |
| 404 | 资源不存在 | 请求的文档或集合不存在 | 检查资源ID是否正确,资源是否已被删除 |
| 422 | 验证错误 | 请求参数验证失败 | 检查错误详情中的具体字段和错误信息 |
| 429 | 请求频率超限 | 短时间内发送过多请求 | 减少请求频率或实现请求限流机制 |
| 500 | 服务器内部错误 | 服务器处理请求时发生错误 | 检查服务器日志或联系技术支持 |
错误排查流程图
开始
│
├─> 收到错误响应
│
├─> 检查状态码
│ │
│ ├─> 401/403 -> 检查认证状态和权限
│ │ │
│ │ ├─> 令牌过期 -> 重新获取令牌
│ │ └─> 权限不足 -> 申请相应权限
│ │
│ ├─> 400/422 -> 检查请求参数
│ │ │
│ │ ├─> 参数缺失 -> 添加必填参数
│ │ └─> 格式错误 -> 修正参数格式
│ │
│ ├─> 404 -> 验证资源是否存在
│ │ │
│ │ ├─> ID错误 -> 使用正确ID
│ │ └─> 资源已删除 -> 恢复资源或使用其他资源
│ │
│ ├─> 429 -> 减少请求频率
│ │
│ └─> 500 -> 联系技术支持
│
└─> 问题解决,重新发送请求
接口性能优化建议
批量操作技巧
-
分页查询优化
- 使用合理的分页大小(建议20-50条/页)
- 实现增量同步机制,通过
updatedAt参数只获取更新的内容 - 避免过深的分页,当
offset过大时考虑使用游标分页
-
批量请求策略
- 对于多个独立操作,考虑合并为批量请求(如适用)
- 实现请求队列,控制并发请求数量
- 避免短时间内发送大量相同类型的请求
-
数据筛选优化
- 使用
collectionId、statusFilter等参数减少返回数据量 - 仅请求需要的字段,避免获取冗余数据
- 合理设置排序方式,减少服务器排序负担
- 使用
缓存策略
-
客户端缓存
- 对不常变化的资源(如文档列表、集合信息)进行本地缓存
- 设置合理的缓存过期时间
- 实现缓存失效机制,在数据更新时主动清除缓存
-
请求优化
- 使用条件请求(如If-Modified-Since)减少不必要的数据传输
- 实现请求合并,减少网络往返次数
- 对大型文档内容考虑分段加载
-
缓存实现示例
Python:
import requests
import json
from datetime import datetime, timedelta
import hashlib
# 简单的内存缓存实现
cache = {}
def get_cached_document(document_id, token):
cache_key = hashlib.md5(f"doc_{document_id}".encode()).hexdigest()
# 检查缓存是否存在且未过期(5分钟)
if cache_key in cache:
cached_data, timestamp = cache[cache_key]
if datetime.now() - timestamp < timedelta(minutes=5):
return cached_data
# 缓存未命中,从API获取
url = "https://your-outline-instance.com/api/documents.info"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {token}"
}
data = {"id": document_id}
response = requests.post(url, headers=headers, data=json.dumps(data))
result = response.json()
# 更新缓存
cache[cache_key] = (result, datetime.now())
return result
完整调用流程示例
以下是一个完整的文档管理流程示例,包括创建、更新、查询和删除文档:
Python:
import requests
import json
class OutlineAPI:
def __init__(self, base_url, token):
self.base_url = base_url
self.headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {token}"
}
def create_document(self, title, collection_id, text="", publish=True):
url = f"{self.base_url}/api/documents.create"
data = {
"title": title,
"collectionId": collection_id,
"text": text,
"publish": publish
}
response = requests.post(url, headers=self.headers, data=json.dumps(data))
return response.json()
def update_document(self, document_id, title=None, text=None):
url = f"{self.base_url}/api/documents.update"
data = {"id": document_id}
if title:
data["title"] = title
if text:
data["text"] = text
response = requests.post(url, headers=self.headers, data=json.dumps(data))
return response.json()
def get_document(self, document_id):
url = f"{self.base_url}/api/documents.info"
data = {"id": document_id}
response = requests.post(url, headers=self.headers, data=json.dumps(data))
return response.json()
def delete_document(self, document_id, permanent=False):
url = f"{self.base_url}/api/documents.delete"
data = {
"id": document_id,
"permanent": permanent
}
response = requests.post(url, headers=self.headers, data=json.dumps(data))
return response.json()
# 使用示例
api = OutlineAPI("https://your-outline-instance.com", "YOUR_JWT_TOKEN")
# 创建文档
create_result = api.create_document(
"API使用示例",
"col_789",
text="{\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\",\"content\":[{\"type\":\"text\",\"text\":\"这是通过API创建的文档示例\"}]}]}"
)
document_id = create_result["data"]["id"]
print(f"创建文档成功: {document_id}")
# 获取文档详情
document = api.get_document(document_id)
print(f"文档标题: {document['data']['document']['title']}")
# 更新文档
update_result = api.update_document(document_id, title="更新后的API使用示例")
print(f"更新文档成功: {update_result}")
# 删除文档(放入回收站)
delete_result = api.delete_document(document_id)
print(f"删除文档成功: {delete_result}")
JavaScript:
class OutlineAPI {
constructor(baseUrl, token) {
this.baseUrl = baseUrl;
this.headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
};
}
async createDocument(title, collectionId, text = "", publish = true) {
const url = `${this.baseUrl}/api/documents.create`;
const data = {
title,
collectionId,
text,
publish
};
const response = await fetch(url, {
method: 'POST',
headers: this.headers,
body: JSON.stringify(data)
});
return response.json();
}
async updateDocument(documentId, title = null, text = null) {
const url = `${this.baseUrl}/api/documents.update`;
const data = { id: documentId };
if (title) data.title = title;
if (text) data.text = text;
const response = await fetch(url, {
method: 'POST',
headers: this.headers,
body: JSON.stringify(data)
});
return response.json();
}
async getDocument(documentId) {
const url = `${this.baseUrl}/api/documents.info`;
const data = { id: documentId };
const response = await fetch(url, {
method: 'POST',
headers: this.headers,
body: JSON.stringify(data)
});
return response.json();
}
async deleteDocument(documentId, permanent = false) {
const url = `${this.baseUrl}/api/documents.delete`;
const data = {
id: documentId,
permanent
};
const response = await fetch(url, {
method: 'POST',
headers: this.headers,
body: JSON.stringify(data)
});
return response.json();
}
}
// 使用示例
const api = new OutlineAPI("https://your-outline-instance.com", "YOUR_JWT_TOKEN");
async function runExample() {
// 创建文档
const createResult = await api.createDocument(
"API使用示例",
"col_789",
JSON.stringify({
type: 'doc',
content: [{
type: 'paragraph',
content: [{
type: 'text',
text: '这是通过API创建的文档示例'
}]
}]
})
);
const documentId = createResult.data.id;
console.log(`创建文档成功: ${documentId}`);
// 获取文档详情
const document = await api.getDocument(documentId);
console.log(`文档标题: ${document.data.document.title}`);
// 更新文档
const updateResult = await api.updateDocument(documentId, "更新后的API使用示例");
console.log(`更新文档成功:`, updateResult);
// 删除文档(放入回收站)
const deleteResult = await api.deleteDocument(documentId);
console.log(`删除文档成功:`, deleteResult);
}
runExample();
接口调用频率限制
为了保护系统稳定性,API接口有调用频率限制:
- 普通接口:每分钟25次
- 搜索接口:每分钟100次
当超过限制时,接口将返回429状态码。建议实现请求限流机制,避免触发限制。
[!NOTE] 企业版用户可以联系支持团队申请更高的API调用配额。
总结
本指南详细介绍了Outline API的核心功能、使用方法和最佳实践。通过这些接口,您可以灵活地与Outline知识库进行交互,实现文档的创建、查询、更新、删除等操作,以及权限管理和高级搜索功能。
无论是构建第三方集成、自动化脚本还是自定义前端,Outline API都提供了强大而灵活的接口支持。遵循本文档中的最佳实践,可以帮助您构建高效、可靠的集成方案。
如需了解更多接口详情,请参考项目源代码中的路由定义文件。
GLM-5.1GLM-5.1是智谱迄今最智能的旗舰模型,也是目前全球最强的开源模型。GLM-5.1大大提高了代码能力,在完成长程任务方面提升尤为显著。和此前分钟级交互的模型不同,它能够在一次任务中独立、持续工作超过8小时,期间自主规划、执行、自我进化,最终交付完整的工程级成果。Jinja00
MiniMax-M2.7MiniMax-M2.7 是我们首个深度参与自身进化过程的模型。M2.7 具备构建复杂智能体应用框架的能力,能够借助智能体团队、复杂技能以及动态工具搜索,完成高度精细的生产力任务。Python00- QQwen3.5-397B-A17BQwen3.5 实现了重大飞跃,整合了多模态学习、架构效率、强化学习规模以及全球可访问性等方面的突破性进展,旨在为开发者和企业赋予前所未有的能力与效率。Jinja00
HY-Embodied-0.5这是一套专为现实世界具身智能打造的基础模型。该系列模型采用创新的混合Transformer(Mixture-of-Transformers, MoT) 架构,通过潜在令牌实现模态特异性计算,显著提升了细粒度感知能力。Jinja00
LongCat-AudioDiT-1BLongCat-AudioDiT 是一款基于扩散模型的文本转语音(TTS)模型,代表了当前该领域的最高水平(SOTA),它直接在波形潜空间中进行操作。00
ERNIE-ImageERNIE-Image 是由百度 ERNIE-Image 团队开发的开源文本到图像生成模型。它基于单流扩散 Transformer(DiT)构建,并配备了轻量级的提示增强器,可将用户的简短输入扩展为更丰富的结构化描述。凭借仅 80 亿的 DiT 参数,它在开源文本到图像模型中达到了最先进的性能。该模型的设计不仅追求强大的视觉质量,还注重实际生成场景中的可控性,在这些场景中,准确的内容呈现与美观同等重要。特别是,ERNIE-Image 在复杂指令遵循、文本渲染和结构化图像生成方面表现出色,使其非常适合商业海报、漫画、多格布局以及其他需要兼具视觉质量和精确控制的内容创作任务。它还支持广泛的视觉风格,包括写实摄影、设计导向图像以及更多风格化的美学输出。Jinja00