Install
openclaw skills install tapd-apiTAPD API 完整集成。实现 18 个模块、70+ API 方法,支持 OAuth 和 Basic Auth 认证。涵盖需求、任务、缺陷、迭代、测试、Wiki、工时等所有 TAPD 功能。
openclaw skills install tapd-api完整的 TAPD 开放平台集成,实现所有 TAPD API 模块。基于 TAPD PHP SDK 用 Python 重新实现。
tapd.json 读取 OAuth 配置所有配置存储在 tapd.json 文件中,支持多工作空间:
{
"oauth": {
"clientId": "your-client-id",
"clientSecret": "your-client-secret"
},
"workspaces": [
{
"id": "12345678",
"name": "项目A",
"default": true
},
{
"id": "87654321",
"name": "项目B"
}
]
}
| 参数 | 必需 | 说明 |
|---|---|---|
oauth.clientId | 是 | TAPD OAuth 应用 ID |
oauth.clientSecret | 是 | TAPD OAuth 应用密钥 |
workspaces | 是 | 工作空间列表 |
workspaces[].id | 是 | 工作空间 ID |
workspaces[].name | 否 | 工作空间名称(便于识别) |
workspaces[].default | 否 | 是否为默认工作空间 |
https://www.tapd.cn/12345678/ → workspace_id 是 12345678# 创建 tapd.json
cat > tapd.json << 'EOF'
{
"oauth": {
"clientId": "your-client-id",
"clientSecret": "your-client-secret"
},
"workspaces": [
{
"id": "12345678",
"name": "我的项目",
"default": true
}
]
}
EOF
# 设置权限
chmod 600 tapd.json
from scripts.tapd_client import TapdClient
import json
# 读取配置
with open('tapd.json') as f:
config = json.load(f)
# 获取默认工作空间
default_workspace = next(
(ws for ws in config['workspaces'] if ws.get('default')),
config['workspaces'][0]
)
# 初始化客户端
client = TapdClient(
auth_type='oauth',
client_id=config['oauth']['clientId'],
client_secret=config['oauth']['clientSecret'],
workspace_id=default_workspace['id']
)
# 获取需求列表
stories = client.story.list(
workspace_id=default_workspace['id'],
limit=10
)
print(f"获取到 {len(stories)} 条需求")
# 遍历所有工作空间
for workspace in config['workspaces']:
print(f"工作空间: {workspace['name']}")
client = TapdClient(
auth_type='oauth',
client_id=config['oauth']['clientId'],
client_secret=config['oauth']['clientSecret'],
workspace_id=workspace['id']
)
stories = client.story.list(workspace_id=workspace['id'], limit=5)
print(f" 需求数: {len(stories)}")
# 设置环境变量(从配置文件读取)
export TAPD_CLIENT_ID=$(cat tapd.json | jq -r '.oauth.clientId')
export TAPD_CLIENT_SECRET=$(cat tapd.json | jq -r '.oauth.clientSecret')
export TAPD_WORKSPACE_ID=$(cat tapd.json | jq -r '.workspace_id')
# 使用命令行工具
./scripts/tapd-api.sh story list --limit 10
./scripts/tapd-api.sh story count
./scripts/tapd-api.sh bug list --status new
stories = client.get_stories(limit=10) for story in stories: print(f"{story['id']}: {story['name']}")
story_detail = client.get_story(story_id="1112345678001000001")
tasks = client.get_tasks(limit=5)
bugs = client.get_bugs(limit=5)
## 📖 API 认证流程
### OAuth 流程图
┌─────────────────────────────────────────────────────────┐ │ 1. 从 tapd.json 读取 clientId + clientSecret │ └─────────────────────────────────────────────────────────┘ ↓ ┌─────────────────────────────────────────────────────────┐ │ 2. POST /tokens/request_token │ │ grant_type=client_credentials │ │ Authorization: Basic base64(clientId:clientSecret) │ └─────────────────────────────────────────────────────────┘ ↓ ┌─────────────────────────────────────────────────────────┐ │ 3. 获取 access_token (有效期 7200 秒 / 2 小时) │ └─────────────────────────────────────────────────────────┘ ↓ ┌─────────────────────────────────────────────────────────┐ │ 4. 调用 TAPD API │ │ Authorization: Bearer <access_token> │ └─────────────────────────────────────────────────────────┘
### 认证代码示例
```bash
# Shell 方式
CLIENT_ID="your-client-id"
CLIENT_SECRET="your-client-secret"
# 获取 access_token
ACCESS_TOKEN=$(curl -s -u "$CLIENT_ID:$CLIENT_SECRET" \
-d "grant_type=client_credentials" \
"https://api.tapd.cn/tokens/request_token" \
| python3 -c "import json, sys; print(json.load(sys.stdin)['data']['access_token'])")
# 调用 API
curl -H "Authorization: Bearer $ACCESS_TOKEN" \
"https://api.tapd.cn/stories?workspace_id=12345678&limit=10"
| 方法 | 端点 | 参数 | 说明 |
|---|---|---|---|
| GET | /stories | workspace_id, limit, page, status | 获取需求列表 |
| GET | /stories/count | workspace_id, status | 获取需求数量 |
| POST | /stories | workspace_id, name, description | 创建需求 |
| POST | /stories | workspace_id, id, ... | 更新需求 |
| 方法 | 端点 | 参数 | 说明 |
|---|---|---|---|
| GET | /tasks | workspace_id, limit, page | 获取任务列表 |
| POST | /tasks | workspace_id, name, ... | 创建/更新任务 |
| 方法 | 端点 | 参数 | 说明 |
|---|---|---|---|
| GET | /bugs | workspace_id, limit, page, status | 获取缺陷列表 |
| POST | /bugs | workspace_id, title, ... | 创建/更新缺陷 |
| 方法 | 端点 | 参数 | 说明 |
|---|---|---|---|
| GET | /iterations | workspace_id, limit, page | 获取迭代列表 |
/workspaces/projects - 获取项目列表/releases - 发布计划/tcases - 测试用例/comments - 评论# 使用命令行工具(自动过滤)
./scripts/tapd-api.sh stories 50 | python3 -c "
import json, sys
data = json.load(sys.stdin)
for item in data['data']:
story = item['Story']
if story.get('priority') == '4': # High priority
print(f\"{story['id']}: {story['name']}\")
"
from scripts.tapd_oauth_client import TapdOAuthClient
client = TapdOAuthClient()
new_story = client.create_story(
name="【新功能】实现用户登录",
description="需求描述:\n1. 支持邮箱登录\n2. 支持手机号登录",
priority="4" # High
)
print(f"创建成功: {new_story['id']}")
client = TapdOAuthClient()
# 获取所有 planning 状态的需求
stories = client.get_stories(status="planning", limit=100)
# 批量更新为进行中
for story in stories:
client.update_story(
story_id=story['id'],
status="status_3" # 进行中
)
scripts/tapd-api.shShell 命令行工具,支持快速查询。
优点:
限制:
scripts/tapd_oauth_client.pyPython 客户端库,支持完整功能。
优点:
推荐用法:
不要提交 tapd.json 到 Git
# .gitignore
tapd.json
tapd-*.json
设置文件权限
chmod 600 tapd.json
使用环境变量(可选)
export TAPD_CLIENT_ID="your-id"
export TAPD_CLIENT_SECRET="your-secret"
export TAPD_WORKSPACE_ID="12345678"
定期更换密钥
原因: OAuth 应用未被授权访问项目
解决:
症状: 返回 401 Unauthorized
解决:
原因: 配置的 workspace_id 不存在或无权限
解决:
/workspaces/projects API 列出可访问的项目Python 客户端会缓存 access_token:
# Token 缓存到 ~/.tapd_token_cache.json
# 有效期内不会重复请求
# 批量获取(推荐)
stories = client.get_stories(limit=100)
# 逐个获取(不推荐)
for id in story_ids:
story = client.get_story(id) # 会触发多次 API 请求
TAPD API 有频率限制,建议:
limit 参数批量获取作者: OpenClaw Community
许可: MIT
支持: https://github.com/openclaw/skills