跳转到内容

API 参考

Knoself 提供 REST API,方便开发者集成和扩展功能。

https://knoself.com/api

所有受保护的 API 需要在请求头中包含 JWT Token:

Authorization: Bearer YOUR_TOKEN_HERE

所有 API 返回 JSON 格式数据:

{
"status": "success",
"data": { ... }
}
POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "your_password"
}

响应:

{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "123",
"email": "user@example.com"
}
}
POST /api/auth/register
Content-Type: application/json
{
"email": "user@example.com",
"password": "your_password",
"name": "Your Name"
}
GET /api/user/profile
Authorization: Bearer YOUR_TOKEN

响应:

{
"user": {
"id": "123",
"email": "user@example.com",
"name": "Your Name"
}
}
POST /api/sync
Authorization: Bearer YOUR_TOKEN
Content-Type: application/json
{
"device_id": "device_123",
"timestamp": 1706626800,
"data": {
"notes": [...],
"tags": [...]
}
}

响应:

{
"status": "success",
"message": "data synced successfully",
"synced_items": 10
}
{
"error": "error message here"
}
状态码说明
400请求参数错误
401未授权(token 无效或过期)
403禁止访问
404资源不存在
429请求过于频繁
500服务器错误
  • 每个 IP 每分钟最多 100 个请求
  • 超出限制返回 429 Too Many Requests
// 使用 fetch API
const response = await fetch('https://knoself.com/api/user/profile', {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
});
const data = await response.json();
import requests
headers = {
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json',
}
response = requests.get(
'https://knoself.com/api/user/profile',
headers=headers
)
data = response.json()