Use this API to retrieve information about SSH keys, manage a user’s SSH and GPG keys, and manage SSH certificates for top-level groups and the instance.

Queries about deploy key fingerprints also retrieve information about the projects using that key. If you use a SHA256 fingerprint in an API call, URL-encode the fingerprint.

Managing group SSH certificates requires the Owner role for a top-level group.

Managing instance SSH certificates requires administrator access.

Retrieve user by SSH key fingerprint

GET /api/v4/keys

Retrieves user by SSH key or deploy key fingerprint. For a deploy key, the response also includes the projects that use the key. Deploy keys are bound to the creating user. Administrators only.

Parameters

NameTypeDescription
fingerprint
Query, required
StringFingerprint of an SSH key or deploy key. URL-encode SHA256 fingerprints: / is %2F and : is %3A
Example: ba:81:59:68:d7:6c:cd:02:02:bf:6a:9b:55:4e:af:d1

Responses

CodeDescriptionSchema
200OKAPIEntitiesSSHKeyWithUser
400Bad Request—

Retrieve user by SSH key ID

GET /api/v4/keys/{id}

Retrieves user by SSH key ID. Administrators only.

Parameters

NameTypeDescription
id
Path, required
String or integerID of the SSH key
Example: 2

Responses

CodeDescriptionSchema
200OKAPIEntitiesSSHKeyWithUser
400Bad Request—
404Not Found—

List all GPG keys

GET /api/v4/user/gpg_keys

Lists all GPG keys for the currently authenticated user.

Parameters

NameTypeDescription
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesGpgKey
400Bad Request—

Add a GPG key

POST /api/v4/user/gpg_keys

Adds a GPG key for the currently authenticated user.

Request body (application/json)

PropertyTypeDescription
key
Required
StringPublic key value of the GPG key

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesGpgKey
400Bad Request—

Retrieve a GPG key

GET /api/v4/user/gpg_keys/{key_id}

Retrieves a GPG key for the currently authenticated user.

Parameters

NameTypeDescription
key_id
Path, required
IntegerID of the GPG key

Responses

CodeDescriptionSchema
200OKAPIEntitiesGpgKey
400Bad Request—
404Not Found—

Delete a GPG key

DELETE /api/v4/user/gpg_keys/{key_id}

Deletes a GPG key from your user account.

Parameters

NameTypeDescription
key_id
Path, required
IntegerID of the GPG key

Responses

CodeDescriptionSchema
204No Content—
400Bad Request—
404Not Found—

List all SSH keys

GET /api/v4/user/keys

Lists all SSH keys for the currently authenticated user.

Parameters

NameTypeDescription
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesSSHKey
400Bad Request—

Add an SSH key

POST /api/v4/user/keys

Adds an SSH key for the currently authenticated user. If the key or its fingerprint is already in use, returns a validation error with the message has already been taken.

Request body (application/json)

PropertyTypeDescription
expires_atString (date-time)Date when the SSH key expires
key
Required
StringPublic key value of the SSH key
title
Required
StringTitle of the SSH key
usage_typeStringUsage scope for the key
Allowed values: auth_and_signing, auth, signing
Default: auth_and_signing

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesSSHKey
400Bad Request—

Retrieve an SSH key

GET /api/v4/user/keys/{key_id}

Retrieves a specified SSH key for the currently authenticated user.

Parameters

NameTypeDescription
key_id
Path, required
IntegerID of the SSH key

Responses

CodeDescriptionSchema
200OKAPIEntitiesSSHKey
400Bad Request—
404Not Found—

Delete an SSH key

DELETE /api/v4/user/keys/{key_id}

Deletes a specified SSH key from the currently authenticated user.

Parameters

NameTypeDescription
key_id
Path, required
IntegerID of the SSH key

Responses

CodeDescriptionSchema
200OKAPIEntitiesSSHKey
400Bad Request—
404Not Found—

List all GPG keys for a user

GET /api/v4/users/{id}/gpg_keys

Lists all GPG keys for a specified user account. This endpoint does not require authentication.

Parameters

NameTypeDescription
id
Path, required
IntegerID of the user
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesGpgKey
400Bad Request—
404Not Found—

Retrieve a GPG key for a user

GET /api/v4/users/{id}/gpg_keys/{key_id}

Retrieves a GPG key for a specified user account. This endpoint does not require authentication.

Parameters

NameTypeDescription
id
Path, required
IntegerID of the user
key_id
Path, required
IntegerID of the GPG key

Responses

CodeDescriptionSchema
200OKAPIEntitiesGpgKey
400Bad Request—
404Not Found—

Delete a GPG key for a user

DELETE /api/v4/users/{id}/gpg_keys/{key_id}

Deletes a GPG key from a specified user account. Administrators only.

Parameters

NameTypeDescription
id
Path, required
IntegerID of the user
key_id
Path, required
IntegerID of the GPG key

Responses

CodeDescriptionSchema
204No Content—
400Bad Request—
404Not Found—

Retrieve an SSH key for a user

GET /api/v4/users/{id}/keys/{key_id}

Retrieves an SSH key for a specified user account. This endpoint does not require authentication.

Parameters

NameTypeDescription
id
Path, required
IntegerID of the user
key_id
Path, required
IntegerID of the SSH key

Responses

CodeDescriptionSchema
200OKAPIEntitiesSSHKey
400Bad Request—
404Not Found—

Delete an SSH key for a user

DELETE /api/v4/users/{id}/keys/{key_id}

Deletes an SSH key from a specified user account. Administrators only.

Parameters

NameTypeDescription
id
Path, required
IntegerID of the user
key_id
Path, required
IntegerID of the SSH key

Responses

CodeDescriptionSchema
200OKAPIEntitiesSSHKey
400Bad Request—
404Not Found—

List all SSH keys for a user

GET /api/v4/users/{user_id}/keys

Lists all SSH keys for a specified user account. This endpoint does not require authentication.

Parameters

NameTypeDescription
user_id
Path, required
StringID or username of the user
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesSSHKey
400Bad Request—
404Not Found—

Add an SSH key for a user

POST /api/v4/users/{user_id}/keys

Adds an SSH key for a specified user account. This also adds an audit event. If the key or its fingerprint is already in use, returns a validation error with the message has already been taken. Administrators only.

Parameters

NameTypeDescription
user_id
Path, required
IntegerID of the user

Request body (application/json)

PropertyTypeDescription
expires_atString (date-time)Date when the SSH key expires
key
Required
StringPublic key value of the SSH key
title
Required
StringTitle of the SSH key
usage_typeStringUsage scope for the key
Allowed values: auth_and_signing, auth, signing
Default: auth_and_signing

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesSSHKey
400Bad Request—
404Not Found—

Schemas

Objects returned by the operations above and objects nested in their request bodies.

APIEntitiesCustomAttribute

PropertyTypeDescription
keyStringExample: foo
valueStringExample: bar

APIEntitiesGpgKey

PropertyTypeDescription
created_atString (date-time)Example: 2017-09-05T09:17:46.264Z
idInteger (int64)Example: 1
keyStringExample: -----BEGIN PGP PUBLIC KEY BLOCK-----

APIEntitiesIdentity

PropertyTypeDescription
extern_uidStringID of the user at the identity provider
providerStringName of the identity provider, such as google_oauth2 or group_saml

APIEntitiesSSHKey

PropertyTypeDescription
created_atString (date-time)Creation date and time of the key in ISO 8601 format
Example: 2015-09-03T07:24:44.627Z
expires_atString (date-time)Expiration date and time of the key in ISO 8601 format
Example: 2020-09-03T07:24:44.627Z
idInteger (int64)ID of the key
Example: 1
keyStringContent of the key
Example: ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt1256k6Yjz\ GGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCdd\ NaP0L+hM7zhFNzjFvpaMgJw0=
last_used_atString (date-time)Last usage date and time of the key in ISO 8601 format
Example: 2020-09-03T07:24:44.627Z
titleStringTitle of the key
Example: Sample key 25
usage_typeStringUsage type of the key: auth, signing, or auth_and_signing. Deploy keys always use auth_and_signing
Example: auth

APIEntitiesSSHKeyWithUser

PropertyTypeDescription
created_atString (date-time)Creation date and time of the key in ISO 8601 format
Example: 2015-09-03T07:24:44.627Z
expires_atString (date-time)Expiration date and time of the key in ISO 8601 format
Example: 2020-09-03T07:24:44.627Z
idInteger (int64)ID of the key
Example: 1
keyStringContent of the key
Example: ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt1256k6Yjz\ GGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCdd\ NaP0L+hM7zhFNzjFvpaMgJw0=
last_used_atString (date-time)Last usage date and time of the key in ISO 8601 format
Example: 2020-09-03T07:24:44.627Z
titleStringTitle of the key
Example: Sample key 25
usage_typeStringUsage type of the key: auth, signing, or auth_and_signing. Deploy keys always use auth_and_signing
Example: auth
userAPIEntitiesUserPublicUser associated with the key

APIEntitiesUserPublic

PropertyTypeDescription
avatar_pathStringExample: /user/avatar/28/The-Big-Lebowski-400-400.png
avatar_urlStringURL of the user’s avatar
Example: https://gravatar.com/avatar/1
bioStringBiography of the user
botBoolean—
can_create_groupBooleanIf true, the user can create groups
Example: true
can_create_projectBooleanIf true, the user can create projects
Example: true
color_scheme_idIntegerColor scheme ID of the user
Example: 1
commit_emailString—
confirmed_atString (date-time)Confirmation date and time of the user in ISO 8601 format
Example: 2015-09-03T07:24:01.670Z
created_atString (date-time)Creation date and time of the user account in ISO 8601 format
current_sign_in_atString (date-time)Current sign-in date and time of the user in ISO 8601 format. Updated when the user signs in to GitLab, at most once an hour
Example: 2015-09-03T07:24:01.670Z
custom_attributesArray of APIEntitiesCustomAttribute—
discordStringDiscord user ID of the user
emailStringEmail address of the user
Example: john@example.com
externalBooleanIf true, the user is external
followersString—
followingString—
githubStringGitHub username of the user
idInteger (int64)ID of the user
Example: 1
identitiesArray of APIEntitiesIdentityIdentities associated with the user. An identity with the group_saml provider also has saml_provider_id
is_followedString—
job_titleStringJob title of the user
last_activity_onString (date-time)Last activity date of the user
Example: 2015-09-03T07:24:01.670Z
last_sign_in_atString (date-time)Last sign-in date and time of the user in ISO 8601 format
Example: 2015-09-03T07:24:01.670Z
linkedinStringLinkedIn username of the user
local_timeString—
locationStringLocation of the user
lockedBooleanIf true, the user account is locked, and the user cannot sign in until the lock expires or an administrator unlocks the account
nameStringName of the user. For a bot user, **** if the current user cannot read the bot’s project or group
Example: Administrator
organizationStringOrganization of the user
preferred_languageStringExample: en
private_profileBooleanIf true, the user’s profile is private
Example: false
projects_limitIntegerProject limit of the user
Example: 10
pronounsStringPronouns of the user
public_emailStringPublic email address of the user
Example: john@example.com
stateStringState of the user account. Possible values: active, blocked, ldap_blocked, blocked_pending_approval, banned, or deactivated
Example: active
theme_idIntegerTheme ID of the user
Example: 2
twitterStringTwitter username of the user
two_factor_enabledBooleanIf true, two-factor authentication is enabled for the user
Example: true
usernameStringUsername of the user
Example: admin
web_urlStringURL of the user’s profile
Example: https://gitlab.example.com/root
website_urlStringWebsite of the user
work_informationString—