{"meta":{"title":"适用于标签的 REST API 终结点","intro":"使用 REST API 管理存储库、议题和拉取请求的标签。","product":"REST API","breadcrumbs":[{"href":"/zh/rest","title":"REST API"},{"href":"/zh/rest/issues","title":"问题"},{"href":"/zh/rest/issues/labels","title":"标签"}],"documentType":"article"},"body":"# 适用于标签的 REST API 终结点\n\n使用 REST API 管理存储库、议题和拉取请求的标签。\n\n## 关于标签\n\n可以使用 REST API 管理存储库的标签，以及在议题和拉取请求中添加或删除标签。 每个拉取请求都是一个议题，但并非每个议题都是拉取请求。 因此，“问题”终结点中为这两项功能提供了“共享”操作，如操作代理人、标签和里程碑。\n\n> [!NOTE]\n> Most endpoints use `Authorization: Bearer <YOUR-TOKEN>` and `Accept: application/vnd.github+json` headers, plus `X-GitHub-Api-Version: 2026-03-10`. Curl examples below omit these standard headers for brevity.\n\n## List labels for an issue\n\n```\nGET /repos/{owner}/{repo}/issues/{issue_number}/labels\n```\n\nLists all labels for an issue.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`issue_number`** (integer) (required)\n  The number that identifies the issue.\n\n- **`per_page`** (integer)\n  The number of results per page (max 100). For more information, see \"Using pagination in the REST API.\"\n  Default: `30`\n\n- **`page`** (integer)\n  The page number of the results to fetch. For more information, see \"Using pagination in the REST API.\"\n  Default: `1`\n\n### HTTP response status codes\n\n- **200** - OK\n\n- **301** - Moved permanently\n\n- **404** - Resource not found\n\n- **410** - Gone\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/repos/OWNER/REPO/issues/ISSUE_NUMBER/labels\n```\n\n**Response schema (Status: 200):**\n\nArray of `Label`:\n  * `id`: required, integer, format: int64\n  * `node_id`: required, string\n  * `url`: required, string, format: uri\n  * `name`: required, string\n  * `description`: required, string or null\n  * `color`: required, string\n  * `default`: required, boolean\n\n## Add labels to an issue\n\n```\nPOST /repos/{owner}/{repo}/issues/{issue_number}/labels\n```\n\nAdds labels to an issue.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`issue_number`** (integer) (required)\n  The number that identifies the issue.\n\n#### Body parameters\n\n- **`labels`** (array)\n  The labels to add to the issue's existing labels. You can also pass an array of labels directly, but GitHub recommends passing an object with the labels key. To replace all of the labels for an issue, use \"Set labels for an issue.\"\n\n### HTTP response status codes\n\n- **200** - OK\n\n- **301** - Moved permanently\n\n- **404** - Resource not found\n\n- **410** - Gone\n\n- **422** - Validation failed, or the endpoint has been spammed.\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  https://api.github.com/repos/OWNER/REPO/issues/ISSUE_NUMBER/labels \\\n  -d '{\n  \"labels\": [\n    \"bug\",\n    \"enhancement\"\n  ]\n}'\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [List labels for an issue](#list-labels-for-an-issue).\n\n## Set labels for an issue\n\n```\nPUT /repos/{owner}/{repo}/issues/{issue_number}/labels\n```\n\nRemoves any previous labels and sets the new labels for an issue.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`issue_number`** (integer) (required)\n  The number that identifies the issue.\n\n#### Body parameters\n\n- **`labels`** (array of strings)\n  The names of the labels to set for the issue. The labels you set replace any existing labels. You can pass an empty array to remove all labels. Alternatively, you can pass a single label as a string or an array of labels directly, but GitHub recommends passing an object with the labels key. You can also add labels to the existing labels for an issue. For more information, see \"Add labels to an issue.\"\n\n### HTTP response status codes\n\n- **200** - OK\n\n- **301** - Moved permanently\n\n- **404** - Resource not found\n\n- **410** - Gone\n\n- **422** - Validation failed, or the endpoint has been spammed.\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PUT \\\n  https://api.github.com/repos/OWNER/REPO/issues/ISSUE_NUMBER/labels \\\n  -d '{\n  \"labels\": [\n    \"bug\",\n    \"enhancement\"\n  ]\n}'\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [List labels for an issue](#list-labels-for-an-issue).\n\n## Remove all labels from an issue\n\n```\nDELETE /repos/{owner}/{repo}/issues/{issue_number}/labels\n```\n\nRemoves all labels from an issue.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`issue_number`** (integer) (required)\n  The number that identifies the issue.\n\n### HTTP response status codes\n\n- **204** - No Content\n\n- **301** - Moved permanently\n\n- **404** - Resource not found\n\n- **410** - Gone\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  https://api.github.com/repos/OWNER/REPO/issues/ISSUE_NUMBER/labels\n```\n\n**Response schema (Status: 204):**\n\n## Remove a label from an issue\n\n```\nDELETE /repos/{owner}/{repo}/issues/{issue_number}/labels/{name}\n```\n\nRemoves the specified label from the issue, and returns the remaining labels on the issue. This endpoint returns a 404 Not Found status if the label does not exist.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`issue_number`** (integer) (required)\n  The number that identifies the issue.\n\n- **`name`** (string) (required)\n\n### HTTP response status codes\n\n- **200** - OK\n\n- **301** - Moved permanently\n\n- **404** - Resource not found\n\n- **410** - Gone\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  https://api.github.com/repos/OWNER/REPO/issues/ISSUE_NUMBER/labels/NAME\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [List labels for an issue](#list-labels-for-an-issue).\n\n## List labels for a repository\n\n```\nGET /repos/{owner}/{repo}/labels\n```\n\nLists all labels for a repository.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`per_page`** (integer)\n  The number of results per page (max 100). For more information, see \"Using pagination in the REST API.\"\n  Default: `30`\n\n- **`page`** (integer)\n  The page number of the results to fetch. For more information, see \"Using pagination in the REST API.\"\n  Default: `1`\n\n### HTTP response status codes\n\n- **200** - OK\n\n- **404** - Resource not found\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/repos/OWNER/REPO/labels\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [List labels for an issue](#list-labels-for-an-issue).\n\n## Create a label\n\n```\nPOST /repos/{owner}/{repo}/labels\n```\n\nCreates a label for the specified repository with the given name and color. The name and color parameters are required. The color must be a valid hexadecimal color code.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n#### Body parameters\n\n- **`name`** (string) (required)\n  The name of the label. Emoji can be added to label names, using either native emoji or colon-style markup. For example, typing :strawberry: will render the emoji . For a full list of available emoji and codes, see \"Emoji cheat sheet.\"\n\n- **`color`** (string)\n  The hexadecimal color code for the label, without the leading #.\n\n- **`description`** (string)\n  A short description of the label. Must be 100 characters or fewer.\n\n### HTTP response status codes\n\n- **201** - Created\n\n- **404** - Resource not found\n\n- **422** - Validation failed, or the endpoint has been spammed.\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X POST \\\n  https://api.github.com/repos/OWNER/REPO/labels \\\n  -d '{\n  \"name\": \"bug\",\n  \"description\": \"Something isn't working\",\n  \"color\": \"f29513\"\n}'\n```\n\n**Response schema (Status: 201):**\n\n* `id`: required, integer, format: int64\n* `node_id`: required, string\n* `url`: required, string, format: uri\n* `name`: required, string\n* `description`: required, string or null\n* `color`: required, string\n* `default`: required, boolean\n\n## Get a label\n\n```\nGET /repos/{owner}/{repo}/labels/{name}\n```\n\nGets a label using the given name.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`name`** (string) (required)\n\n### HTTP response status codes\n\n- **200** - OK\n\n- **404** - Resource not found\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/repos/OWNER/REPO/labels/NAME\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Create a label](#create-a-label).\n\n## Update a label\n\n```\nPATCH /repos/{owner}/{repo}/labels/{name}\n```\n\nUpdates a label using the given label name.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`name`** (string) (required)\n\n#### Body parameters\n\n- **`new_name`** (string)\n  The new name of the label. Emoji can be added to label names, using either native emoji or colon-style markup. For example, typing :strawberry: will render the emoji . For a full list of available emoji and codes, see \"Emoji cheat sheet.\"\n\n- **`color`** (string)\n  The hexadecimal color code for the label, without the leading #.\n\n- **`description`** (string)\n  A short description of the label. Must be 100 characters or fewer.\n\n- **`archived`** (boolean)\n  Whether to archive or unarchive the label. Archived labels cannot be added to issues or pull requests. For more information, see \"Archiving labels.\"\n\n### HTTP response status codes\n\n- **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X PATCH \\\n  https://api.github.com/repos/OWNER/REPO/labels/NAME \\\n  -d '{\n  \"new_name\": \"bug :bug:\",\n  \"description\": \"Small bug fix required\",\n  \"color\": \"b01f26\"\n}'\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Create a label](#create-a-label).\n\n## Delete a label\n\n```\nDELETE /repos/{owner}/{repo}/labels/{name}\n```\n\nDeletes a label using the given label name.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`name`** (string) (required)\n\n### HTTP response status codes\n\n- **204** - No Content\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X DELETE \\\n  https://api.github.com/repos/OWNER/REPO/labels/NAME\n```\n\n**Response schema (Status: 204):**\n\n## List labels for issues in a milestone\n\n```\nGET /repos/{owner}/{repo}/milestones/{milestone_number}/labels\n```\n\nLists labels for issues in a milestone.\n\n### Parameters\n\n#### Headers\n\n- **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Path and query parameters\n\n- **`owner`** (string) (required)\n  The account owner of the repository. The name is not case sensitive.\n\n- **`repo`** (string) (required)\n  The name of the repository without the .git extension. The name is not case sensitive.\n\n- **`milestone_number`** (integer) (required)\n  The number that identifies the milestone.\n\n- **`per_page`** (integer)\n  The number of results per page (max 100). For more information, see \"Using pagination in the REST API.\"\n  Default: `30`\n\n- **`page`** (integer)\n  The page number of the results to fetch. For more information, see \"Using pagination in the REST API.\"\n  Default: `1`\n\n### HTTP response status codes\n\n- **200** - OK\n\n### Code examples\n\n#### Example\n\n**Request:**\n\n```curl\ncurl -L \\\n  -X GET \\\n  https://api.github.com/repos/OWNER/REPO/milestones/MILESTONE_NUMBER/labels\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [List labels for an issue](#list-labels-for-an-issue)."}