跳至主要内容
REST API 现已版本化。 有关更多信息,请参阅 "关于 API 版本控制”。

通知的 REST API 端点

使用 REST API 管理 GitHub 通知。

关于 GitHub 通知

这些端点仅支持使用个人访问令牌(经典)进行身份验证。有关更多信息,请参阅“管理个人访问令牌”。

你可以使用 REST API 来管理 GitHub 通知。有关通知的更多信息,请参阅“关于通知”。

对这些端点的所有调用都需要 notificationsrepo 范围。你需要 repo 范围才能从各自的端点访问问题和提交。

通知以“线程”的形式返回。线程包含有关问题、拉取请求或提交的当前讨论的信息。

通知经过优化,可使用 Last-Modified 标头进行轮询。如果没有新通知,你将看到 304 未修改 响应,保持你的当前速率限制不变。有一个 X-Poll-Interval 标头,指定允许你轮询的频率(以秒为单位)。在服务器负载较高的时期,时间可能会增加。请遵守标头。

# Add authentication to your requests
$ curl -I https://api.github.com/notifications
HTTP/2 200
Last-Modified: Thu, 25 Oct 2012 15:16:27 GMT
X-Poll-Interval: 60

# Pass the Last-Modified header exactly
$ curl -I https://api.github.com/notifications
$    -H "If-Modified-Since: Thu, 25 Oct 2012 15:16:27 GMT"
> HTTP/2 304
> X-Poll-Interval: 60

关于通知原因

这些 GET 端点返回 reason 键。这些 reason 对应于触发通知的事件。

收到通知可能有几个潜在的 reason

原因名称说明
approval_requested请求你审阅并批准部署。有关更多信息,请参阅“审阅部署”。
assign你被分配到该问题。
author你创建了该线程。
comment你在该线程上发表了评论。
ci_activity你触发的 GitHub Actions 工作流运行已完成。
invitation你接受了对存储库进行贡献的邀请。
manual你订阅了该线程(通过问题或拉取请求)。
member_feature_requested组织成员已请求启用一项功能,例如草稿拉取请求或 Copilot。
mention你在内容中被特别@提及
review_requested你或你所在的团队被请求审阅拉取请求。
security_alertGitHub 在你的存储库中发现了安全漏洞
security_advisory_credit你因对安全公告做出贡献而获得认可。
state_change你更改了线程状态(例如,关闭问题或合并拉取请求)。
subscribed你正在关注该存储库。
team_mention你属于被提及的团队。

请注意,reason 会根据每个线程进行修改,并且如果以后通知中的 reason 不同,则可能会更改。

例如,如果你是一个问题的作者,那么该问题上的后续通知的 reason 将为 author。如果你随后在同一问题上被@提及,那么你之后获取的通知的 reason 将为 mention。无论你是否再次被提及,reason 都会保持为 mention

列出经过身份验证用户的通知

按最近更新时间排序,列出当前用户的所有通知。

“列出经过身份验证用户的通知”的细粒度访问令牌

此端点适用于以下细粒度令牌类型

细粒度令牌必须具有以下权限设置

  • “元数据”存储库权限(读取)“通知”用户权限(读取)

“列出经过身份验证用户的通知”的参数

标头
名称、类型、描述
accept string

建议设置为 application/vnd.github+json

查询参数
名称、类型、描述
all boolean

如果为 true,则显示标记为已读的通知。

默认: false

participating boolean

如果为 true,则仅显示用户直接参与或被提及的通知。

默认: false

since string

仅显示自给定时间后上次更新的结果。此时间戳采用 ISO 8601 格式:YYYY-MM-DDTHH:MM:SSZ

before 字符串

仅显示在给定时间之前更新的通知。这是 ISO 8601 格式的时间戳:YYYY-MM-DDTHH:MM:SSZ

page 整数

要获取的结果的页码。有关详细信息,请参阅“在 REST API 中使用分页”。

默认值: 1

per_page 整数

每页的结果数(最大 50)。有关详细信息,请参阅“在 REST API 中使用分页”。

默认值: 50

“列出经过身份验证用户的通知”的 HTTP 响应状态代码

状态代码说明
200

正常

304

未修改

401

需要身份验证

403

禁止

422

验证失败,或端点已收到垃圾邮件。

“列出经过身份验证用户的通知”的代码示例

请求示例

get/notifications
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/notifications

响应

状态:200
[ { "id": "1", "repository": { "id": 1296269, "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", "name": "Hello-World", "full_name": "octocat/Hello-World", "owner": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/octocat/Hello-World", "description": "This your first repo!", "fork": false, "url": "https://api.github.com/repos/octocat/Hello-World", "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", "events_url": "https://api.github.com/repos/octocat/Hello-World/events", "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", "git_url": "git:github.com/octocat/Hello-World.git", "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", "ssh_url": "[email protected]:octocat/Hello-World.git", "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", "hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks" }, "subject": { "title": "Greetings", "url": "https://api.github.com/repos/octokit/octokit.rb/issues/123", "latest_comment_url": "https://api.github.com/repos/octokit/octokit.rb/issues/comments/123", "type": "Issue" }, "reason": "subscribed", "unread": true, "updated_at": "2014-11-07T22:01:45Z", "last_read_at": "2014-11-07T22:01:45Z", "url": "https://api.github.com/notifications/threads/1", "subscription_url": "https://api.github.com/notifications/threads/1/subscription" } ]

将通知标记为已读

将当前用户的全部通知标记为“已读”。如果通知数量太多,无法在一个请求中完成,您将收到一个 202 已接受 状态,GitHub 将运行一个异步进程来将通知标记为“已读”。要检查是否仍有“未读”通知,您可以使用 列出经过身份验证用户的通知 端点并传递查询参数 all=false

“将通知标记为已读”的细粒度访问令牌

此端点不适用于 GitHub 应用用户访问令牌、GitHub 应用安装访问令牌或细粒度个人访问令牌。

“将通知标记为已读”的参数

标头
名称、类型、描述
accept string

建议设置为 application/vnd.github+json

正文参数
名称、类型、描述
last_read_at string

描述上次检查通知的时间点。此时间点之后更新的任何内容均不会被标记为已读。如果您省略此参数,则所有通知都将被标记为已读。此时间戳采用 ISO 8601 格式:YYYY-MM-DDTHH:MM:SSZ。默认值:当前时间戳。

read boolean

通知是否已读。

“将通知标记为已读”的 HTTP 响应状态代码

状态代码说明
202

已接受

205

重置内容

304

未修改

401

需要身份验证

403

禁止

“将通知标记为已读”的代码示例

请求示例

put/notifications
curl -L \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/notifications \ -d '{"last_read_at":"2022-06-10T00:00:00Z","read":true}'

响应

状态:202
{ "message": "Unread notifications couldn't be marked in a single request. Notifications are being marked as read in the background." }

获取线程

获取有关通知线程的信息。

“获取线程”的细粒度访问令牌

此端点不适用于 GitHub 应用用户访问令牌、GitHub 应用安装访问令牌或细粒度个人访问令牌。

“获取线程”的参数

标头
名称、类型、描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
thread_id integer Required

通知线程的唯一标识符。这对应于在检索通知时(例如,使用 GET /notifications 操作)在 id 字段中返回的值。

“获取线程”的 HTTP 响应状态代码

状态代码说明
200

正常

304

未修改

401

需要身份验证

403

禁止

“获取线程”的代码示例

请求示例

获取/通知/主题/{主题_id}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/notifications/threads/THREAD_ID

响应

状态:200
{ "id": "1", "repository": { "id": 1296269, "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", "name": "Hello-World", "full_name": "octocat/Hello-World", "owner": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/octocat/Hello-World", "description": "This your first repo!", "fork": false, "url": "https://api.github.com/repos/octocat/Hello-World", "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", "events_url": "https://api.github.com/repos/octocat/Hello-World/events", "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", "git_url": "git:github.com/octocat/Hello-World.git", "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", "ssh_url": "[email protected]:octocat/Hello-World.git", "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", "hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks" }, "subject": { "title": "Greetings", "url": "https://api.github.com/repos/octokit/octokit.rb/issues/123", "latest_comment_url": "https://api.github.com/repos/octokit/octokit.rb/issues/comments/123", "type": "Issue" }, "reason": "subscribed", "unread": true, "updated_at": "2014-11-07T22:01:45Z", "last_read_at": "2014-11-07T22:01:45Z", "url": "https://api.github.com/notifications/threads/1", "subscription_url": "https://api.github.com/notifications/threads/1/subscription" }

将主题标记为已读

将主题标记为“已读”。将主题标记为“已读”相当于在 GitHub 上的通知收件箱中单击通知:https://github.com/notifications

用于“将主题标记为已读”的细粒度访问令牌

此端点不适用于 GitHub 应用用户访问令牌、GitHub 应用安装访问令牌或细粒度个人访问令牌。

用于“将主题标记为已读”的参数

标头
名称、类型、描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
thread_id integer Required

通知线程的唯一标识符。这对应于在检索通知时(例如,使用 GET /notifications 操作)在 id 字段中返回的值。

用于“将主题标记为已读”的 HTTP 响应状态代码

状态代码说明
205

重置内容

304

未修改

403

禁止

用于“将主题标记为已读”的代码示例

请求示例

修补程序/通知/主题/{主题_id}
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/notifications/threads/THREAD_ID

重置内容

状态:205

将主题标记为已完成

将主题标记为“已完成”。将主题标记为“已完成”相当于在 GitHub 上的通知收件箱中将通知标记为已完成:https://github.com/notifications

用于“将主题标记为已完成”的细粒度访问令牌

此端点不适用于 GitHub 应用用户访问令牌、GitHub 应用安装访问令牌或细粒度个人访问令牌。

用于“将主题标记为已完成”的参数

标头
名称、类型、描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
thread_id integer Required

通知线程的唯一标识符。这对应于在检索通知时(例如,使用 GET /notifications 操作)在 id 字段中返回的值。

用于“将主题标记为已完成”的 HTTP 响应状态代码

状态代码说明
204

无内容

用于“将主题标记为已完成”的代码示例

请求示例

删除/通知/主题/{主题_id}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/notifications/threads/THREAD_ID

无内容

状态:204

获取经过身份验证用户的主题订阅

这会检查当前用户是否订阅了主题。您还可以获取存储库订阅

请注意,仅当用户参与对话时才会生成订阅,例如,他们回复了主题,被@提及或手动订阅了主题。

用于“获取经过身份验证用户的主题订阅”的细粒度访问令牌

此端点不适用于 GitHub 应用用户访问令牌、GitHub 应用安装访问令牌或细粒度个人访问令牌。

用于“获取经过身份验证用户的主题订阅”的参数

标头
名称、类型、描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
thread_id integer Required

通知线程的唯一标识符。这对应于在检索通知时(例如,使用 GET /notifications 操作)在 id 字段中返回的值。

用于“获取经过身份验证用户的主题订阅”的 HTTP 响应状态代码

状态代码说明
200

正常

304

未修改

401

需要身份验证

403

禁止

用于“获取经过身份验证用户的主题订阅”的代码示例

请求示例

获取/通知/主题/{主题_id}/订阅
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/notifications/threads/THREAD_ID/subscription

响应

状态:200
{ "subscribed": true, "ignored": false, "reason": null, "created_at": "2012-10-06T21:34:12Z", "url": "https://api.github.com/notifications/threads/1/subscription", "thread_url": "https://api.github.com/notifications/threads/1" }

设置线程订阅

如果您正在关注某个存储库,则默认情况下会收到所有线程的通知。使用此端点来忽略线程的未来通知,直到您对该线程发表评论或获得@提及

您还可以使用此端点来订阅当前未收到通知的线程,或订阅您之前已忽略的线程。

取消订阅您未关注的存储库中的对话在功能上等同于删除线程订阅端点。

“设置线程订阅”的细粒度访问令牌

此端点不适用于 GitHub 应用用户访问令牌、GitHub 应用安装访问令牌或细粒度个人访问令牌。

“设置线程订阅”的参数

标头
名称、类型、描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
thread_id integer Required

通知线程的唯一标识符。这对应于在检索通知时(例如,使用 GET /notifications 操作)在 id 字段中返回的值。

正文参数
名称、类型、描述
ignored boolean

是否阻止来自线程的所有通知。

默认: false

“设置线程订阅”的 HTTP 响应状态代码

状态代码说明
200

正常

304

未修改

401

需要身份验证

403

禁止

“设置线程订阅”的代码示例

请求示例

put/notifications/threads/{thread_id}/subscription
curl -L \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/notifications/threads/THREAD_ID/subscription \ -d '{"ignored":false}'

响应

状态:200
{ "subscribed": true, "ignored": false, "reason": null, "created_at": "2012-10-06T21:34:12Z", "url": "https://api.github.com/notifications/threads/1/subscription", "thread_url": "https://api.github.com/notifications/threads/1" }

删除线程订阅

静音对话的所有未来通知,直到您对该线程发表评论或获得@提及。如果您正在关注该线程的存储库,您仍会收到通知。要忽略您正在关注的存储库的未来通知,请使用设置线程订阅端点并将ignore设置为true

“删除线程订阅”的细粒度访问令牌

此端点不适用于 GitHub 应用用户访问令牌、GitHub 应用安装访问令牌或细粒度个人访问令牌。

“删除线程订阅”的参数

标头
名称、类型、描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
thread_id integer Required

通知线程的唯一标识符。这对应于在检索通知时(例如,使用 GET /notifications 操作)在 id 字段中返回的值。

“删除线程订阅”的 HTTP 响应状态代码

状态代码说明
204

无内容

304

未修改

401

需要身份验证

403

禁止

“删除线程订阅”的代码示例

请求示例

delete/notifications/threads/{thread_id}/subscription
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/notifications/threads/THREAD_ID/subscription

响应

状态:204

列出经过身份验证用户的存储库通知

列出指定存储库中当前用户的所有通知。

“列出经过身份验证用户的存储库通知”的细粒度访问令牌

此端点不适用于 GitHub 应用用户访问令牌、GitHub 应用安装访问令牌或细粒度个人访问令牌。

“列出经过身份验证用户的存储库通知”的参数

标头
名称、类型、描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
owner string 必需

存储库的帐户所有者。名称不区分大小写。

repo string 必需

不带 .git 扩展名的存储库名称。名称不区分大小写。

查询参数
名称、类型、描述
all boolean

如果为 true,则显示标记为已读的通知。

默认: false

participating boolean

如果为 true,则仅显示用户直接参与或被提及的通知。

默认: false

since string

仅显示自给定时间后上次更新的结果。此时间戳采用 ISO 8601 格式:YYYY-MM-DDTHH:MM:SSZ

before 字符串

仅显示在给定时间之前更新的通知。这是 ISO 8601 格式的时间戳:YYYY-MM-DDTHH:MM:SSZ

per_page 整数

每页的结果数(最大 100)。有关详细信息,请参阅“在 REST API 中使用分页”。

默认: 30

page 整数

要获取的结果的页码。有关详细信息,请参阅“在 REST API 中使用分页”。

默认值: 1

“列出经过身份验证用户的存储库通知”的 HTTP 响应状态代码

状态代码说明
200

正常

“列出经过身份验证用户的存储库通知”的代码示例

请求示例

get/repos/{owner}/{repo}/notifications
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/notifications

响应

状态:200
[ { "id": "1", "repository": { "id": 1296269, "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", "name": "Hello-World", "full_name": "octocat/Hello-World", "owner": { "login": "octocat", "id": 1, "node_id": "MDQ6VXNlcjE=", "avatar_url": "https://github.com/images/error/octocat_happy.gif", "gravatar_id": "", "url": "https://api.github.com/users/octocat", "html_url": "https://github.com/octocat", "followers_url": "https://api.github.com/users/octocat/followers", "following_url": "https://api.github.com/users/octocat/following{/other_user}", "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}", "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/octocat/subscriptions", "organizations_url": "https://api.github.com/users/octocat/orgs", "repos_url": "https://api.github.com/users/octocat/repos", "events_url": "https://api.github.com/users/octocat/events{/privacy}", "received_events_url": "https://api.github.com/users/octocat/received_events", "type": "User", "site_admin": false }, "private": false, "html_url": "https://github.com/octocat/Hello-World", "description": "This your first repo!", "fork": false, "url": "https://api.github.com/repos/octocat/Hello-World", "archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}", "assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}", "blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}", "branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}", "collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}", "comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}", "commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}", "compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}", "contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}", "contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors", "deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments", "downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads", "events_url": "https://api.github.com/repos/octocat/Hello-World/events", "forks_url": "https://api.github.com/repos/octocat/Hello-World/forks", "git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}", "git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}", "git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}", "git_url": "git:github.com/octocat/Hello-World.git", "issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}", "issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}", "issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}", "keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}", "labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}", "languages_url": "https://api.github.com/repos/octocat/Hello-World/languages", "merges_url": "https://api.github.com/repos/octocat/Hello-World/merges", "milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}", "notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}", "pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}", "releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}", "ssh_url": "[email protected]:octocat/Hello-World.git", "stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers", "statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}", "subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers", "subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription", "tags_url": "https://api.github.com/repos/octocat/Hello-World/tags", "teams_url": "https://api.github.com/repos/octocat/Hello-World/teams", "trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}", "hooks_url": "http://api.github.com/repos/octocat/Hello-World/hooks" }, "subject": { "title": "Greetings", "url": "https://api.github.com/repos/octokit/octokit.rb/issues/123", "latest_comment_url": "https://api.github.com/repos/octokit/octokit.rb/issues/comments/123", "type": "Issue" }, "reason": "subscribed", "unread": true, "updated_at": "2014-11-07T22:01:45Z", "last_read_at": "2014-11-07T22:01:45Z", "url": "https://api.github.com/notifications/threads/1", "subscription_url": "https://api.github.com/notifications/threads/1/subscription" } ]

将存储库通知标记为已读

将存储库中的所有通知标记为当前用户的“已读”。如果通知数量太大,无法在一个请求中完成,您将收到 202 已接受 状态,GitHub 将运行一个异步进程将通知标记为“已读”。要检查是否还有任何“未读”通知,可以使用 列出经过身份验证用户的存储库通知 端点,并传递查询参数 all=false

“将存储库通知标记为已读”的细粒度访问令牌

此端点不适用于 GitHub 应用用户访问令牌、GitHub 应用安装访问令牌或细粒度个人访问令牌。

“将存储库通知标记为已读”的参数

标头
名称、类型、描述
accept string

建议设置为 application/vnd.github+json

路径参数
名称、类型、描述
owner string 必需

存储库的帐户所有者。名称不区分大小写。

repo string 必需

不带 .git 扩展名的存储库名称。名称不区分大小写。

正文参数
名称、类型、描述
last_read_at string

描述上次检查通知的时间点。此时间点之后更新的任何内容均不会被标记为已读。如果您省略此参数,则所有通知都将被标记为已读。此时间戳采用 ISO 8601 格式:YYYY-MM-DDTHH:MM:SSZ。默认值:当前时间戳。

“将仓库通知标记为已读”的 HTTP 响应状态代码

状态代码说明
202

已接受

205

重置内容

“将仓库通知标记为已读”的代码示例

请求示例

put/repos/{owner}/{repo}/notifications
curl -L \ -X PUT \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/notifications \ -d '{"last_read_at":"2019-01-01T00:00:00Z"}'

响应

状态:202
{ "message": "Unread notifications couldn't be marked in a single request. Notifications are being marked as read in the background." }