Jira
2026-03-27
新闻来源:网淘吧
围观:10
电脑广告
手机广告
Jira
通过托管的OAuth认证访问Jira Cloud API。使用JQL搜索问题、创建和管理问题,并自动化工作流。
快速开始
# First, get your cloud ID
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/jira/oauth/token/accessible-resources')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
# Then search issues
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/jira/ex/jira/{cloudId}/rest/api/3/search/jql?jql=project%3DKEY&maxResults=10')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
基础URL
https://gateway.maton.ai/jira/{native-api-path}
将{native-api-path}替换为实际的Jira API端点路径。网关将请求代理到api.atlassian.com并自动注入您的OAuth令牌。
获取Cloud ID
Jira Cloud需要一个cloud ID。请先获取它:
GET /jira/oauth/token/accessible-resources
响应:
[{
"id": "62909843-b784-4c35-b770-e4e2a26f024b",
"url": "https://yoursite.atlassian.net",
"name": "yoursite"
}]
认证
所有请求都需要在Authorization头部包含Maton API密钥:
Authorization: Bearer $MATON_API_KEY
环境变量:将您的API密钥设置为MATON_API_KEY:
export MATON_API_KEY="YOUR_API_KEY"
获取您的API密钥
- 登录或注册账户于maton.ai
- 前往maton.ai/settings
- 复制您的 API 密钥
连接管理
请在以下地址管理您的 Jira OAuth 连接https://ctrl.maton.ai。
列出连接
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections?app=jira&status=ACTIVE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
创建连接
python <<'EOF'
import urllib.request, os, json
data = json.dumps({'app': 'jira'}).encode()
req = urllib.request.Request('https://ctrl.maton.ai/connections', data=data, method='POST')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Content-Type', 'application/json')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
获取连接
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
响应:
{
"connection": {
"connection_id": "21fd90f9-5935-43cd-b6c8-bde9d915ca80",
"status": "ACTIVE",
"creation_time": "2025-12-08T07:20:53.488460Z",
"last_updated_time": "2026-01-31T20:03:32.593153Z",
"url": "https://connect.maton.ai/?session_token=...",
"app": "jira",
"metadata": {}
}
}
在浏览器中打开返回的网址以完成 OAuth 授权。
删除连接
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections/{connection_id}', method='DELETE')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
指定连接
如果您有多个 Jira 连接,请使用Maton-Connection请求头来指定要使用哪一个:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://gateway.maton.ai/jira/ex/jira/{cloudId}/rest/api/3/project')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
req.add_header('Maton-Connection', '21fd90f9-5935-43cd-b6c8-bde9d915ca80')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
如果省略,网关将使用默认(最早创建的)活动连接。
API 参考
项目
列出项目
GET /jira/ex/jira/{cloudId}/rest/api/3/project
获取项目
GET /jira/ex/jira/{cloudId}/rest/api/3/project/{projectKeyOrId}
问题
搜索问题 (JQL)
GET /jira/ex/jira/{cloudId}/rest/api/3/search/jql?jql=project%3DKEY%20order%20by%20created%20DESC&maxResults=20&fields=summary,status,assignee
获取问题
GET /jira/ex/jira/{cloudId}/rest/api/3/issue/{issueIdOrKey}
创建问题
POST /jira/ex/jira/{cloudId}/rest/api/3/issue
Content-Type: application/json
{
"fields": {
"project": {"key": "PROJ"},
"summary": "Issue summary",
"issuetype": {"name": "Task"}
}
}
更新问题
PUT /jira/ex/jira/{cloudId}/rest/api/3/issue/{issueIdOrKey}
Content-Type: application/json
{
"fields": {
"summary": "Updated summary"
}
}
删除问题
DELETE /jira/ex/jira/{cloudId}/rest/api/3/issue/{issueIdOrKey}
分配问题
PUT /jira/ex/jira/{cloudId}/rest/api/3/issue/{issueIdOrKey}/assignee
Content-Type: application/json
{
"accountId": "712020:5aff718e-6fe0-4548-82f4-f44ec481e5e7"
}
状态转换
获取状态转换
GET /jira/ex/jira/{cloudId}/rest/api/3/issue/{issueIdOrKey}/transitions
转换问题状态
POST /jira/ex/jira/{cloudId}/rest/api/3/issue/{issueIdOrKey}/transitions
Content-Type: application/json
{
"transition": {"id": "31"}
}
评论
获取评论
GET /jira/ex/jira/{cloudId}/rest/api/3/issue/{issueIdOrKey}/comment
添加评论
POST /jira/ex/jira/{cloudId}/rest/api/3/issue/{issueIdOrKey}/comment
Content-Type: application/json
{
"body": {
"type": "doc",
"version": 1,
"content": [{"type": "paragraph", "content": [{"type": "text", "text": "Comment text"}]}]
}
}
用户
获取当前用户
GET /jira/ex/jira/{cloudId}/rest/api/3/myself
搜索用户
GET /jira/ex/jira/{cloudId}/rest/api/3/user/search?query=john
元数据
列出问题类型
GET /jira/ex/jira/{cloudId}/rest/api/3/issuetype
列出优先级
GET /jira/ex/jira/{cloudId}/rest/api/3/priority
列出状态
GET /jira/ex/jira/{cloudId}/rest/api/3/status
代码示例
JavaScript
// Get cloud ID first
const resources = await fetch(
'https://gateway.maton.ai/jira/oauth/token/accessible-resources',
{ headers: { 'Authorization': `Bearer ${process.env.MATON_API_KEY}` } }
).then(r => r.json());
const cloudId = resources[0].id;
// Search issues
const issues = await fetch(
`https://gateway.maton.ai/jira/ex/jira/${cloudId}/rest/api/3/search/jql?jql=project=KEY`,
{ headers: { 'Authorization': `Bearer ${process.env.MATON_API_KEY}` } }
).then(r => r.json());
Python
import os
import requests
headers = {'Authorization': f'Bearer {os.environ["MATON_API_KEY"]}'}
# Get cloud ID
resources = requests.get(
'https://gateway.maton.ai/jira/oauth/token/accessible-resources',
headers=headers
).json()
cloud_id = resources[0]['id']
# Search issues
issues = requests.get(
f'https://gateway.maton.ai/jira/ex/jira/{cloud_id}/rest/api/3/search/jql',
headers=headers,
params={'jql': 'project=KEY', 'maxResults': 10}
).json()
注意事项
- 始终先使用以下方式获取云ID
/oauth/token/accessible-resources - JQL查询必须是有界的(例如,
project=KEY) - 对JQL查询参数使用URL编码
- 更新、删除、转换操作成功时返回HTTP 204状态码
- Agile API需要额外的OAuth权限范围。如果您收到权限范围错误,请联系Maton支持,邮箱为support@maton.ai,并说明您需要的具体操作/API以及您的使用场景
- 重要提示:使用curl命令时,如果URL中包含方括号(
fields[]、sort[]、records[]),请使用curl -g来禁用全局解析 - 重要提示:当将curl输出通过管道传递给
jq或其他命令时,像$MATON_API_KEY在某些shell环境中可能无法正确展开。通过管道传输时可能会出现"无效API密钥"的错误。
错误处理
| 状态码 | 含义 |
|---|---|
| 400 | 缺少Jira连接或JQL查询无效 |
| 401 | Maton API密钥无效或缺失 |
| 429 | 请求频率受限(每个账户每秒10次请求) |
| 4xx/5xx | 来自Jira API的透传错误 |
故障排除:API密钥问题
- 检查
MATON_API_KEY环境变量是否已设置:
echo $MATON_API_KEY
- 通过列出连接来验证API密钥是否有效:
python <<'EOF'
import urllib.request, os, json
req = urllib.request.Request('https://ctrl.maton.ai/connections')
req.add_header('Authorization', f'Bearer {os.environ["MATON_API_KEY"]}')
print(json.dumps(json.load(urllib.request.urlopen(req)), indent=2))
EOF
故障排除:无效的应用名称
- 确保您的URL路径以
jira开头。例如:
- 正确示例:
https://gateway.maton.ai/jira/ex/jira/{cloudId}/rest/api/3/project - 错误:
https://gateway.maton.ai/ex/jira/{cloudId}/rest/api/3/project
资源
文章底部电脑广告
手机广告位-内容正文底部


微信扫一扫,打赏作者吧~