跳转至

列出当前认证用户的消息通知

GET /api/v5/notifications

获取当前认证用户的消息通知列表,支持按已读状态、消息来源及创建时间范围筛选和分页查询。默认返回全部来源的未读消息,查询不会将消息标记为已读。

访问令牌支持说明

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

是否允许匿名访问

此接口不允许匿名访问

请求参数

参数名 位置 类型 必填 说明
access_token query string 是 用户授权码
state query string 否 读取状态,枚举:unread / read / all;默认 unread(仅未读)
type query string 否 单个消息来源,不传表示全部来源;枚举:pull_request / issue / mention / invitation / pipeline_alert / system
since query string 否 仅查询此时间之后创建的消息,格式 yyyy-MM-dd'T'HH:mm:ssXXX(如 2026-11-01T08:00:00%2B08:00);须早于 before
before query string 否 仅查询此时间之前创建的消息,格式 yyyy-MM-dd'T'HH:mm:ssXXX(如 2026-11-01T08:00:00%2B08:00)
page query integer 否 当前页码,默认 1,须大于 0
per_page query integer 否 每页的项目数,默认 30,取值 1~100

响应参数

字段 类型 必返 可为空 说明
total integer 是 否 符合筛选条件的总条数
list array 是 否 当前页的消息通知
list[].id string 是 否 消息 ID
list[].content string 是 否 消息内容,与消息中心一致,可能包含 HTML
list[].type string 是 否 消息来源,已知来源为 pull_request、issue、mention、invitation、pipeline_alert、system;其他来源保留原始类型
list[].unread boolean 是 否 是否未读
list[].created_at string 是 否 消息创建时间,北京时间,格式 yyyy-MM-dd'T'HH:mm:ssXXX
list[].html_url string 是 否 触发消息的资源页面地址
list[].actor object 是 是 触发人,系统消息可为空
list[].repository object 是 是 所属仓库,非仓库消息为空

list[].actor 对象

字段 类型 必返 可为空 说明
list[].actor.avatar_url string 是 否 头像地址
list[].actor.events_url string 是 否 动态列表 API 地址
list[].actor.followers_url string 是 否 粉丝列表 API 地址
list[].actor.following_url string 是 否 关注列表 API 地址
list[].actor.gists_url string 是 否 代码片段 API 地址
list[].actor.html_url string 是 否 用户或组织的页面地址
list[].actor.id string 是 否 用户或组织的标识
list[].actor.object_id string 是 否 用户对象标识
list[].actor.login string 是 否 用户名或组织路径
list[].actor.member_role string 是 否 成员角色
list[].actor.name string 是 否 用户昵称或组织名称
list[].actor.organizations_url string 是 否 所属组织列表 API 地址
list[].actor.received_events_url string 是 否 接收动态列表 API 地址
list[].actor.remark string 是 否 企业备注名
list[].actor.repos_url string 是 否 仓库列表 API 地址
list[].actor.starred_url string 是 否 收藏仓库列表 API 地址
list[].actor.subscriptions_url string 是 否 订阅列表 API 地址
list[].actor.type string 是 否 对象类型:User 表示用户,Organization 表示组织
list[].actor.url string 是 否 用户或组织的详情 API 地址

list[].repository 对象

字段 类型 必返 可为空 说明
list[].repository.id integer 是 否 仓库 ID
list[].repository.full_name string 是 否 仓库完整路径
list[].repository.human_name string 是 否 仓库完整显示名称
list[].repository.url string 是 否 仓库页面地址

失败响应

该接口在认证失败或参数不合法时返回错误。错误字段名以后端实际返回为准。

400 参数错误

{
  "error": "invalid_request",
  "message": "state must be unread, read or all"
}

401 未认证

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

HTTP 响应状态码

状态码 说明
200 成功(OK)
400 参数错误(Bad Request)
401 需要认证(Requires authentication)
403 禁止访问(Forbidden)

请求示例

参数说明

<token> 替换为你的 AtomGit 用户访问令牌。 state type since before page per_page 均为可选,可按需追加。

cURL

curl -X GET 'https://api.atomgit.com/api/v5/notifications?access_token=<token>&state=unread&page=1&per_page=30' \
  -H 'Accept: application/json'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch(
  "https://api.atomgit.com/api/v5/notifications?access_token=<token>&state=unread&page=1&per_page=30",
  {
    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/notifications",
    params={
        "access_token": "<token>",
        "state": "unread",
        "page": 1,
        "per_page": 30,
    },
    headers={"Accept": "application/json"},
    timeout=10,
)
resp.raise_for_status()

print(resp.json())

响应示例

状态码: 200

{
  "total": 1,
  "list": [
    {
      "id": "b7c6f8d0-1234-4a5b-9c6d-0e1f2a3b4c5d",
      "content": "<p>有人在合并请求 #12 中提到了你</p>",
      "type": "mention",
      "unread": true,
      "created_at": "2024-11-20T13:00:21+08:00",
      "html_url": "https://atomgit.com/octocat/hello-world/merge_requests/12",
      "actor": {
        "id": "10086",
        "login": "octocat",
        "name": "octocat",
        "avatar_url": "https://api.atomgit.com/avatar.png",
        "html_url": "https://atomgit.com/octocat",
        "type": "User"
      },
      "repository": {
        "id": 12345,
        "full_name": "octocat/hello-world",
        "human_name": "hello-world",
        "url": "https://atomgit.com/octocat/hello-world"
      }
    }
  ]
}

错误码

错误码 说明
400 参数错误或请求无法解析
401 未认证或凭证无效(缺少/无效的访问凭证)
403 无权访问该资源
429 请求过于频繁,触发限流
500 系统内部错误

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