跳转至

获取企业某个Issue所有标签

GET /api/v5/enterprises/{enterprise}/issues/{number}/labels

该接口用于获取企业指定 Issue 下的所有标签,返回标签的编号、名称、颜色及链接信息,并支持分页查询。

访问令牌支持说明

  • AtomGit 用户访问令牌(AtomGit user access tokens)

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
enterprise path string 是 企业名(path)
number path integer 是 Issue 编号(全局唯一)
access_token query string 是 用户授权码
page query integer 否 当前的页码,默认 1
per_page query integer 否 每页的数量,最大为 100,默认 100

响应参数

接口返回标签对象数组,每个元素的结构如下:

字段 类型 必返 可为空 说明
id integer 是 否 标签 ID
color string 是 否 标签颜色
name string 是 否 标签名称
url string 是 否 标签链接,当前固定返回空字符串

失败响应

只有 200/成功响应是不够的:调用方需要知道失败长什么样才能写错误处理。

400 参数错误

{
  "error": "invalid_request",
  "message": "参数 number 不合法"
}

401 未认证

{
  "error": "unauthorized",
  "message": "缺少或无效的访问令牌"
}

404 资源不存在

{
  "error": "not_found",
  "message": "企业或 Issue 不存在"
}

错误字段名以后端实际返回为准。

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 参数错误(Bad request)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)
404 资源不存在(Not found)

请求示例

参数说明

示例必须与本文档其余部分自洽,照抄即可调用成功,三条硬性要求:

  1. 认证头必须与「访问令牌支持说明」一致 —— 该节说需要令牌,示例就必须携带 access_token;
  2. 必填参数一个都不能漏 —— 路径参数、必填查询参数必须全部出现在示例里;
  3. 占位符要能替换 —— 统一用 <...> 形式,并在下方说明每个占位符的含义。

<enterprise> 替换为企业名(path); <number> 替换为 Issue 的全局唯一编号; <token> 替换为你的 AtomGit 用户访问令牌。

cURL

curl -X GET 'https://api.atomgit.com/api/v5/enterprises/<enterprise>/issues/<number>/labels?access_token=<token>&page=1&per_page=100' \
  -H 'Accept: application/json'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
  "https://api.atomgit.com/api/v5/enterprises/<enterprise>/issues/<number>/labels?access_token=<token>&page=1&per_page=100",
  {
    headers: {
      "Accept": "application/json",
    },
  },
);

if (!response.ok) {
  throw new Error(`请求失败: ${response.status}`);
}

const data = await response.json();
console.log(data);

Python

import requests

resp = requests.get(
    "https://api.atomgit.com/api/v5/enterprises/<enterprise>/issues/<number>/labels",
    params={
        "access_token": "<token>",
        "page": 1,
        "per_page": 100,
    },
    headers={"Accept": "application/json"},
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

[
  {
    "id": 381445,
    "color": "#008672",
    "name": "help wanted",
    "url": ""
  }
]

错误码

错误码 说明
401 未认证或凭证无效(缺少/无效的访问凭证)
400 参数错误或请求无法解析
404 请求路径或资源不存在
405 请求方法不支持
429 请求过于频繁,触发限流
500 系统内部错误

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc