API 文档
使用 PJT AI API 从外部系统、代理和内部系统管理项目和任务。
https://api.pjt.ai认证
PJT AI API 支持两种认证方式:API 密钥和 JWT 令牌。
API 密钥
API 密钥是外部系统集成的推荐认证方式。从账户设置中生成 API 密钥。
进入账户设置中的 API 密钥部分。
点击「创建新 API 密钥」按钮并输入名称。
安全保存生成的密钥。完整密钥仅在创建时显示。
请求头格式
X-API-Key: pk_live_xxxxxxxxxxxxcURL 示例
curl -X GET "https://api.pjt.ai/api/external/v1/workspaces" \
-H "X-API-Key: pk_live_xxxxxxxxxxxx"JavaScript 示例
const response = await fetch('https://api.pjt.ai/api/external/v1/workspaces', {
method: 'GET',
headers: {
'X-API-Key': 'pk_live_xxxxxxxxxxxx',
'Content-Type': 'application/json',
},
});
const workspaces = await response.json();JWT 令牌
JWT 令牌用于基于用户会话的认证。将登录后颁发的令牌包含在 Authorization 请求头中。
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...docs.sections.rateLimiting
docs.auth.rateLimitDescription
| docs.auth.rateLimitType | docs.auth.rateLimitValue |
|---|---|
| docs.auth.rateLimitPerMinute | 60 |
docs.auth.rateLimitExceeded
{
"error": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Please try again later."
}docs.sections.apiUsage
docs.apiUsage.description
docs.apiUsage.stats.description
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | docs.apiUsage.params.apiKeyId |
响应
{
"apiKeyId": 1,
"todayUsage": 150,
"monthlyUsage": 3420,
"totalUsage": 12500,
"today": "2026-01-20",
"month": "2026-01"
}docs.apiUsage.history.description
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | docs.apiUsage.params.apiKeyId |
days | query | 否 | docs.apiUsage.params.days |
响应
{
"apiKeyId": 1,
"history": [
{ "date": "2026-01-20", "count": 150 },
{ "date": "2026-01-19", "count": 230 },
{ "date": "2026-01-18", "count": 180 }
]
}docs.apiUsage.account.description
响应
{
"accountId": 1,
"monthlyUsage": [
{ "month": "2026-01", "count": 3420 },
{ "month": "2025-12", "count": 4500 },
{ "month": "2025-11", "count": 3200 }
]
}docs.sections.workspaces
docs.workspaces.description
docs.workspaces.list.description
响应
{
"content": [
{
"id": 1,
"name": "My Workspace",
"description": "Main workspace",
"createdAt": "2024-01-10T09:00:00Z"
}
],
"totalElements": 1,
"totalPages": 1,
"page": 0,
"size": 20
}docs.workspaces.get.description
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | docs.workspaces.params.id |
响应
{
"id": 1,
"name": "My Workspace",
"description": "Main workspace",
"members": [...],
"createdAt": "2024-01-10T09:00:00Z"
}项目
创建、读取、更新和删除项目。
获取工作区中的项目列表。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
workspaceId | path | 是 | 工作区 ID |
page | query | 否 | 页码(从 0 开始) |
size | query | 否 | 页面大小(默认:20) |
响应
{
"content": [
{
"id": 1,
"name": "Website Redesign",
"description": "Complete website overhaul",
"status": "IN_PROGRESS",
"startDate": "2024-01-15",
"endDate": "2024-03-30",
"createdAt": "2024-01-10T09:00:00Z"
}
],
"totalElements": 1,
"totalPages": 1,
"page": 0,
"size": 20
}获取项目详情。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | 项目 ID |
响应
{
"id": 1,
"name": "Website Redesign",
"description": "Complete website overhaul",
"status": "IN_PROGRESS",
"startDate": "2024-01-15",
"endDate": "2024-03-30",
"tasks": [...],
"createdAt": "2024-01-10T09:00:00Z"
}创建新项目。
请求体
{
"workspaceId": 1,
"name": "New Project",
"description": "Project description",
"startDate": "2024-01-15",
"endDate": "2024-03-30"
}响应
{
"id": 1,
"name": "New Project",
"description": "Project description",
"status": "PLANNING",
"startDate": "2024-01-15",
"endDate": "2024-03-30",
"createdAt": "2024-01-10T09:00:00Z"
}更新项目信息。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | 项目 ID |
请求体
{
"name": "Updated Project Name",
"status": "IN_PROGRESS"
}响应
{
"id": 1,
"name": "Updated Project Name",
"status": "IN_PROGRESS",
...
}删除项目。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | 项目 ID |
响应
204 No Content任务
管理项目中的任务。
获取项目中的任务列表。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
projectId | path | 是 | 项目 ID |
响应
[
{
"id": 1,
"title": "Design mockups",
"description": "Create initial design mockups",
"status": "IN_PROGRESS",
"priority": "HIGH",
"dueDate": "2024-01-20",
"assignee": { "id": 1, "name": "John Doe" }
}
]docs.tasks.paged.description
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
projectId | path | 是 | 项目 ID |
page | query | 否 | 页码(从 0 开始) |
size | query | 否 | 页面大小(默认:20) |
响应
{
"content": [
{
"id": 1,
"title": "Design mockups",
"description": "Create initial design mockups",
"status": "IN_PROGRESS",
"priority": "HIGH",
"dueDate": "2024-01-20"
}
],
"totalElements": 1,
"totalPages": 1,
"page": 0,
"size": 20
}docs.tasks.get.description
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | docs.tasks.params.taskId |
响应
{
"id": 1,
"title": "Design mockups",
"description": "Create initial design mockups",
"status": "IN_PROGRESS",
"priority": "HIGH",
"dueDate": "2024-01-20",
"assignee": { "id": 1, "name": "John Doe" },
"project": { "id": 1, "name": "Website Redesign" }
}创建新任务。
请求体
{
"projectId": 1,
"title": "New Task",
"description": "Task description",
"priority": "MEDIUM",
"dueDate": "2024-01-25",
"assigneeId": 1
}响应
{
"id": 2,
"title": "New Task",
"description": "Task description",
"status": "TODO",
"priority": "MEDIUM",
"dueDate": "2024-01-25"
}docs.tasks.update.description
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | docs.tasks.params.taskId |
请求体
{
"title": "Updated Task",
"status": "IN_PROGRESS",
"priority": "HIGH"
}响应
{
"id": 1,
"title": "Updated Task",
"status": "IN_PROGRESS",
"priority": "HIGH",
...
}docs.tasks.delete.description
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | docs.tasks.params.taskId |
响应
204 No Contentdocs.tasks.assigned.description
响应
[
{
"id": 1,
"title": "Design mockups",
"description": "Create initial design mockups",
"status": "IN_PROGRESS",
"priority": "HIGH",
"dueDate": "2024-01-20",
"project": { "id": 1, "name": "Website Redesign" }
}
]文档
管理项目文档。
获取项目中的文档列表。
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
projectId | path | 是 | 项目 ID |
响应
[
{
"id": 1,
"title": "Project Requirements",
"type": "SPECIFICATION",
"createdAt": "2024-01-10T09:00:00Z",
"updatedAt": "2024-01-15T14:30:00Z"
}
]docs.documents.paged.description
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
projectId | path | 是 | 项目 ID |
page | query | 否 | 页码(从 0 开始) |
size | query | 否 | 页面大小(默认:20) |
响应
{
"content": [
{
"id": 1,
"title": "Project Requirements",
"type": "SPECIFICATION",
"createdAt": "2024-01-10T09:00:00Z",
"updatedAt": "2024-01-15T14:30:00Z"
}
],
"totalElements": 1,
"totalPages": 1,
"page": 0,
"size": 20
}docs.documents.get.description
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | docs.documents.params.documentId |
响应
{
"id": 1,
"title": "Project Requirements",
"type": "SPECIFICATION",
"content": "Document content here...",
"project": { "id": 1, "name": "Website Redesign" },
"createdAt": "2024-01-10T09:00:00Z",
"updatedAt": "2024-01-15T14:30:00Z"
}创建新文档。
请求体
{
"projectId": 1,
"title": "API Specification",
"type": "SPECIFICATION",
"content": "Document content here..."
}响应
{
"id": 2,
"title": "API Specification",
"type": "SPECIFICATION",
"createdAt": "2024-01-20T10:00:00Z"
}docs.documents.update.description
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | docs.documents.params.documentId |
请求体
{
"title": "Updated Title",
"content": "Updated content..."
}响应
{
"id": 1,
"title": "Updated Title",
"content": "Updated content...",
"updatedAt": "2024-01-20T10:00:00Z"
}docs.documents.delete.description
参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
id | path | 是 | docs.documents.params.documentId |
响应
204 No Content外部集成
将 PJT AI API 与外部自动化工具集成,以自动化您的工作流程。
n8n 配置
要在 n8n 中使用 PJT AI API,请在 HTTP Request 节点中配置认证。
将 HTTP Request 节点添加到您的 n8n 工作流程中。
将认证设置为「Generic Credential Type」。
创建「Header Auth」凭据,并输入 X-API-Key 和您的 API 密钥。
设置基础 URL 并调用 API 端点。
凭据配置
{
"name": "PJT AI API",
"type": "httpHeaderAuth",
"data": {
"name": "X-API-Key",
"value": "pk_live_xxxxxxxxxxxx"
}
}工作流示例
使用 n8n 的工作流程自动化示例。
从 Slack 消息创建项目
当在 Slack 消息中检测到特定关键字时,自动创建新项目。
{
"nodes": [
{
"name": "Slack Trigger",
"type": "n8n-nodes-base.slackTrigger",
"parameters": {
"channel": "#project-requests"
}
},
{
"name": "Create Project",
"type": "n8n-nodes-base.httpRequest",
"parameters": {
"method": "POST",
"url": "https://api.pjt.ai/api/external/v1/projects",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "httpHeaderAuth",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{ "name": "Content-Type", "value": "application/json" }
]
},
"sendBody": true,
"bodyParameters": {
"parameters": [
{ "name": "workspaceId", "value": "1" },
{ "name": "name", "value": "={{ $json.text }}" },
{ "name": "description", "value": "Created from Slack" }
]
}
}
}
]
}逾期任务通知
每天检查逾期任务,并向负责人发送 Slack 通知。
{
"nodes": [
{
"name": "Schedule Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"parameters": {
"rule": { "interval": [{ "field": "hours", "hoursInterval": 1 }] }
}
},
{
"name": "Get Tasks",
"type": "n8n-nodes-base.httpRequest",
"parameters": {
"method": "GET",
"url": "https://api.pjt.ai/api/external/v1/projects/{{projectId}}/tasks",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "httpHeaderAuth",
"qs": { "status": "IN_PROGRESS" }
}
},
{
"name": "Filter Overdue",
"type": "n8n-nodes-base.filter",
"parameters": {
"conditions": {
"dateTime": [{
"value1": "={{ $json.dueDate }}",
"operation": "before",
"value2": "={{ $now }}"
}]
}
}
},
{
"name": "Send Notification",
"type": "n8n-nodes-base.slack",
"parameters": {
"channel": "#alerts",
"text": "Overdue task: {{ $json.title }}"
}
}
]
}从 GitHub Issue 创建任务
当在 GitHub 中创建新 Issue 时,自动创建 PJT AI 任务。
{
"nodes": [
{
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"parameters": {
"path": "github-issue",
"httpMethod": "POST"
}
},
{
"name": "Create Task",
"type": "n8n-nodes-base.httpRequest",
"parameters": {
"method": "POST",
"url": "https://api.pjt.ai/api/external/v1/projects/{{projectId}}/tasks",
"authentication": "predefinedCredentialType",
"nodeCredentialType": "httpHeaderAuth",
"sendBody": true,
"bodyParameters": {
"parameters": [
{ "name": "title", "value": "={{ $json.issue.title }}" },
{ "name": "description", "value": "={{ $json.issue.body }}" },
{ "name": "priority", "value": "MEDIUM" }
]
}
}
}
]
}错误处理
API 使用标准 HTTP 状态码来指示请求成功或失败。
| 状态码 | 含义 | API 使用标准 HTTP 状态码来指示请求成功或失败。 |
|---|---|---|
200 | OK | 请求成功。 |
201 | Created | 资源创建成功。 |
204 | No Content | 请求成功,无返回内容。 |
400 | Bad Request | 错误请求。请检查请求格式。 |
401 | Unauthorized | 需要认证或凭据无效。 |
403 | Forbidden | 无权访问该资源。 |
404 | Not Found | 请求的资源未找到。 |
429 | Too Many Requests | 超出速率限制。请稍后重试。 |
500 | Internal Server Error | 服务器内部错误。 |
错误响应格式
{
"error": {
"code": "VALIDATION_ERROR",
"message": "The request body contains invalid data",
"details": [
{
"field": "name",
"message": "Name is required"
}
]
}
}