{"meta":{"title":"GPG キーの REST API エンドポイント","intro":"REST API を使って、認証されたユーザーの GPG キーを管理します。","product":"REST API","breadcrumbs":[{"href":"/ja/enterprise-cloud@latest/rest","title":"REST API"},{"href":"/ja/enterprise-cloud@latest/rest/users","title":"ユーザー"},{"href":"/ja/enterprise-cloud@latest/rest/users/gpg-keys","title":"GPG キー"}],"documentType":"article"},"body":"# GPG キーの REST API エンドポイント\n\nREST API を使って、認証されたユーザーの GPG キーを管理します。\n\n## ユーザーの GPG キー管理について\n\n`public_key` 応答フィールドで返されるデータは、GPG 形式のキーではありません。 ユーザが GPG キーをアップロードすると、そのキーは解析され、暗号化された公開鍵が抽出、保存されます。 この暗号化キーは、このカテゴリのエンドポイントが返すものです。 このキーは、GPG などのプログラムでの直接使用には適していません。\n\n要求 URL に `{username}` パラメーターが含まれていない場合、応答はサインインしているユーザーに対して行われます (要求で[認証情報](/ja/enterprise-cloud@latest/rest/authentication/authenticating-to-the-rest-api)を渡す必要があります)。 ユーザーが 2 要素認証を有効にしているかどうかなどの追加の個人情報は、基本認証またはの`user`スコープを使用した認証時に含まれます。\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 GPG keys for the authenticated user\n\n```\nGET /user/gpg_keys\n```\n\nLists the current user's GPG keys.\nOAuth app tokens and personal access tokens (classic) need the read:gpg\\_key scope to use this endpoint.\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* **`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* **304** - Not modified\n\n* **401** - Requires authentication\n\n* **403** - Forbidden\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/user/gpg_keys\n```\n\n**Response schema (Status: 200):**\n\nArray of `GPG Key`:\n\n* `id`: required, integer, format: int64\n* `name`: string or null\n* `primary_key_id`: required, integer or null\n* `key_id`: required, string\n* `public_key`: required, string\n* `emails`: required, array of objects:\n  * `email`: string\n  * `verified`: boolean\n* `subkeys`: required, array of objects:\n  * `id`: integer, format: int64\n  * `primary_key_id`: integer\n  * `key_id`: string\n  * `public_key`: string\n  * `emails`: array of objects:\n    * `email`: string\n    * `verified`: boolean\n  * `subkeys`: array of object\n  * `can_sign`: boolean\n  * `can_encrypt_comms`: boolean\n  * `can_encrypt_storage`: boolean\n  * `can_certify`: boolean\n  * `created_at`: string\n  * `expires_at`: string or null\n  * `raw_key`: string or null\n  * `revoked`: boolean\n* `can_sign`: required, boolean\n* `can_encrypt_comms`: required, boolean\n* `can_encrypt_storage`: required, boolean\n* `can_certify`: required, boolean\n* `created_at`: required, string, format: date-time\n* `expires_at`: required, string or null, format: date-time\n* `revoked`: required, boolean\n* `raw_key`: required, string or null\n\n## Create a GPG key for the authenticated user\n\n```\nPOST /user/gpg_keys\n```\n\nAdds a GPG key to the authenticated user's GitHub account.\nOAuth app tokens and personal access tokens (classic) need the write:gpg\\_key scope to use this endpoint.\n\n### Parameters\n\n#### Headers\n\n* **`accept`** (string)\n  Setting to `application/vnd.github+json` is recommended.\n\n#### Body parameters\n\n* **`name`** (string)\n  A descriptive name for the new key.\n\n* **`armored_public_key`** (string) (required)\n  A GPG key in ASCII-armored format.\n\n### HTTP response status codes\n\n* **201** - Created\n\n* **304** - Not modified\n\n* **401** - Requires authentication\n\n* **403** - Forbidden\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/user/gpg_keys \\\n  -d '{\n  \"name\": \"Octocat's GPG Key\",\n  \"armored_public_key\": \"-----BEGIN PGP PUBLIC KEY BLOCK-----\\nVersion: GnuPG v1\\n\\nmQINBFnZ2ZIBEADQ2Z7Z7\\n-----END PGP PUBLIC KEY BLOCK-----\"\n}'\n```\n\n**Response schema (Status: 201):**\n\n* `id`: required, integer, format: int64\n* `name`: string or null\n* `primary_key_id`: required, integer or null\n* `key_id`: required, string\n* `public_key`: required, string\n* `emails`: required, array of objects:\n  * `email`: string\n  * `verified`: boolean\n* `subkeys`: required, array of objects:\n  * `id`: integer, format: int64\n  * `primary_key_id`: integer\n  * `key_id`: string\n  * `public_key`: string\n  * `emails`: array of objects:\n    * `email`: string\n    * `verified`: boolean\n  * `subkeys`: array of object\n  * `can_sign`: boolean\n  * `can_encrypt_comms`: boolean\n  * `can_encrypt_storage`: boolean\n  * `can_certify`: boolean\n  * `created_at`: string\n  * `expires_at`: string or null\n  * `raw_key`: string or null\n  * `revoked`: boolean\n* `can_sign`: required, boolean\n* `can_encrypt_comms`: required, boolean\n* `can_encrypt_storage`: required, boolean\n* `can_certify`: required, boolean\n* `created_at`: required, string, format: date-time\n* `expires_at`: required, string or null, format: date-time\n* `revoked`: required, boolean\n* `raw_key`: required, string or null\n\n## Get a GPG key for the authenticated user\n\n```\nGET /user/gpg_keys/{gpg_key_id}\n```\n\nView extended details for a single GPG key.\nOAuth app tokens and personal access tokens (classic) need the read:gpg\\_key scope to use this endpoint.\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* **`gpg_key_id`** (integer) (required)\n  The unique identifier of the GPG key.\n\n### HTTP response status codes\n\n* **200** - OK\n\n* **304** - Not modified\n\n* **401** - Requires authentication\n\n* **403** - Forbidden\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/user/gpg_keys/GPG_KEY_ID\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [Create a GPG key for the authenticated user](#create-a-gpg-key-for-the-authenticated-user).\n\n## Delete a GPG key for the authenticated user\n\n```\nDELETE /user/gpg_keys/{gpg_key_id}\n```\n\nRemoves a GPG key from the authenticated user's GitHub account.\nOAuth app tokens and personal access tokens (classic) need the admin:gpg\\_key scope to use this endpoint.\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* **`gpg_key_id`** (integer) (required)\n  The unique identifier of the GPG key.\n\n### HTTP response status codes\n\n* **204** - No Content\n\n* **304** - Not modified\n\n* **401** - Requires authentication\n\n* **403** - Forbidden\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 DELETE \\\n  https://api.github.com/user/gpg_keys/GPG_KEY_ID\n```\n\n**Response schema (Status: 204):**\n\n## List GPG keys for a user\n\n```\nGET /users/{username}/gpg_keys\n```\n\nLists the GPG keys for a user. This information is accessible by anyone.\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* **`username`** (string) (required)\n  The handle for the GitHub user account.\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/users/USERNAME/gpg_keys\n```\n\n**Response schema (Status: 200):**\n\nSame response schema as [List GPG keys for the authenticated user](#list-gpg-keys-for-the-authenticated-user)."}