{"meta":{"title":"REST-API-Endpunkte für GPG-Schlüssel","intro":"Verwende die REST-API, um die GPG-Schlüssel authentifizierter Benutzer*innen zu verwalten.","product":"REST-API","breadcrumbs":[{"href":"/de/rest","title":"REST-API"},{"href":"/de/rest/users","title":"Benutzer"},{"href":"/de/rest/users/gpg-keys","title":"GPG-Schlüssel"}],"documentType":"article"},"body":"# REST-API-Endpunkte für GPG-Schlüssel\n\nVerwende die REST-API, um die GPG-Schlüssel authentifizierter Benutzer\\*innen zu verwalten.\n\n## Informationen zur GPG-Schlüsselverwaltung von Benutzer\\*innen\n\nDie im Antwortfeld `public_key` zurückgegebenen Daten sind kein GPG-formatierter Schlüssel. Wenn ein Benutzer einen GPG-Schlüssel hochlädt, wird dieser analysiert, und der kryptografische öffentliche Schlüssel wird extrahiert und gespeichert. Dieser kryptografische Schlüssel wird von den Endpunkten dieser Kategorie zurückgegeben. Dieser Schlüssel ist nicht für die direkte Verwendung in Programmen wie GPG geeignet.\n\nWenn eine Anforderungs-URL keinen `{username}`-Parameter enthält, gilt die Antwort für den*die angemeldete*n Benutzer\\*in (und Sie müssen [Authentifizierungsinformationen](/de/rest/authentication/authenticating-to-the-rest-api) mit Ihrer Anforderung übergeben). Zusätzliche private Informationen, z. B. ob ein Benutzer die zweistufige Authentifizierung aktiviert hat, werden bei der Authentifizierung über OAuth mit dem `user` Zugriffsbereich eingeschlossen.\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)."}