---
title: "Add a new GPG key"
method: POST
path: "/users/{selected_user}/gpg-keys"
tags: ["GPG"]
---

# Add a new GPG key

`POST /users/{selected_user}/gpg-keys`

Adds a new GPG public key to the specified user account and returns the resulting key.

Example:

```
$ curl -X POST -H "Content-Type: application/json" -d
'{"key": "<insert GPG Key>"}'
https://api.bitbucket.org/2.0/users/{d7dd0e2d-3994-4a50-a9ee-d260b6cefdab}/gpg-keys
```

## Request body

- GPGAccountKey — Represents a GPG public key for a user.
  - `type` string, required
  - `owner` Account — An account object.
    - `type` string, required
    - `links` AccountLinks — Links related to an Account.
      - `avatar` Link — A link to a resource related to this object.
        - `href` string, uri
        - `name` string
    - `created_on` string, date-time
    - `display_name` string
    - `uuid` string
  - `key` string — The GPG key value in X format.
  - `key_id` string — The unique identifier for the GPG key
  - `fingerprint` string — The GPG key fingerprint.
  - `parent_fingerprint` string — The fingerprint of the parent key. This value is null unless the current key is a subkey.
  - `name` string — The user-defined label for the GPG key
  - `expires_on` string, date-time
  - `created_on` string, date-time
  - `added_on` string, date-time
  - `last_used` string, date-time
  - `subkeys` GPGAccountKey[]
  - `links` object
    - `self` object — A link to a resource related to this object.
      - `href` string, uri
      - `name` string

## Response `201`

The newly created GPG key.

- GPGAccountKey — Represents a GPG public key for a user.
  - `type` string, required
  - `owner` Account — An account object.
    - `type` string, required
    - `links` AccountLinks — Links related to an Account.
      - `avatar` Link — A link to a resource related to this object.
        - `href` string, uri
        - `name` string
    - `created_on` string, date-time
    - `display_name` string
    - `uuid` string
  - `key` string — The GPG key value in X format.
  - `key_id` string — The unique identifier for the GPG key
  - `fingerprint` string — The GPG key fingerprint.
  - `parent_fingerprint` string — The fingerprint of the parent key. This value is null unless the current key is a subkey.
  - `name` string — The user-defined label for the GPG key
  - `expires_on` string, date-time
  - `created_on` string, date-time
  - `added_on` string, date-time
  - `last_used` string, date-time
  - `subkeys` GPGAccountKey[]
  - `links` object
    - `self` object — A link to a resource related to this object.
      - `href` string, uri
      - `name` string

## Other responses

- `400` — If the submitted key or related value is invalid
- `403` — If the current user does not have permission to add a key for the specified user
- `404` — If the specified user does not exist

---

[API](https://skmtc.net/bitbucket/apis/bitbucket-api.md) · [All operations](https://skmtc.net/bitbucket/apis/bitbucket-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/bitbucket/bitbucket-api/versions/4ec8bd2515c5/schema)
