使用JIRA rest/api/2复制仪表盘时遭遇404错误求助
解决JIRA REST API复制仪表盘返回404的问题
可能的原因及排查修复步骤
1. API端点路径错误
JIRA不同版本的复制仪表盘API路径存在差异:
- 若你使用的是JIRA Server/Data Center旧版本,正确端点应为
/rest/api/2/dashboard/copy,原仪表盘ID需放在请求体而非URL路径中。修改后的代码示例:
import requests from requests.auth import HTTPBasicAuth import json def auth(name, password): return HTTPBasicAuth(name, password) def copy_dashboard(auth, id, name): url = "https://jira.xxx.com/rest/api/2/dashboard/copy" headers = { "Accept": "application/json", "Content-Type": "application/json" } payload = json.dumps({ "originalDashboardId": id, # 新增原仪表盘ID字段 "description": "A dashboard to help auditors identify sample of issues to check.", "editPermissions": [], "name": name, "sharePermissions": [ { "type": "global" } ] }) response = requests.request( "POST", url, data=payload, headers=headers, auth=auth ) print(response.json())
- 若为JIRA Cloud版本,需使用API v3,端点为
/rest/api/3/dashboard/{id}/copy,同时确保请求体字段符合Cloud版本要求。
2. 原仪表盘ID无效或无访问权限
先验证12221这个ID对应的仪表盘是否存在且你有权访问:
def check_dashboard(auth, id): url = f"https://jira.xxx.com/rest/api/2/dashboard/{id}" headers = {"Accept": "application/json"} response = requests.get(url, headers=headers, auth=auth) print(response.status_code, response.json())
如果该接口也返回404,说明ID错误或账号无原仪表盘的查看权限。
3. 账号权限不足
确认你的账号拥有复制仪表盘的权限,且能访问原仪表盘。可以先在JIRA网页端手动尝试复制该仪表盘,若网页端也无法操作,需联系管理员调整权限配置。
内容的提问来源于stack exchange,提问作者nicole
相关产品推荐
相关产品推荐

