{"meta":{"title":"Points de terminaison d’API REST pour les clés GPG","intro":"Utilisez l’API REST pour gérer les clés GPG des utilisateurs authentifiés.","product":"API REST","breadcrumbs":[{"href":"/fr/rest","title":"API REST"},{"href":"/fr/rest/users","title":"Utilisateurs"},{"href":"/fr/rest/users/gpg-keys","title":"Clés GPG"}],"documentType":"article"},"body":"# Points de terminaison d’API REST pour les clés GPG\n\nUtilisez l’API REST pour gérer les clés GPG des utilisateurs authentifiés.\n\n## À propos de l’administration des clés GPG des utilisateurs\n\nLes données retournées dans le champ de réponse `public_key` ne sont pas une clé mise en forme GPG. Lorsqu’un utilisateur charge une clé GPG, elle est analysée, et la clé publique de chiffrement est extraite et stockée. Cette clé de chiffrement est celle qui sera retournée par les points de terminaison de cette catégorie. Cette clé ne convient pas pour une utilisation directe dans des programmes tels que GPG.\n\nSi une URL de requête n’inclut pas de paramètre `{username}`, la réponse est destinée à l’utilisateur connecté (et vous devez transmettre des [informations d’authentification](/fr/rest/overview/authenticating-to-the-rest-api) avec votre demande). Des informations privées supplémentaires, telles que si un utilisateur a activé l’authentification à deux facteurs, sont incluses lors de l’authentification de base via OAuth avec l’étendue `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)."}