Please check gitlab-tutorial

Skip to content

Service account users API

DETAILS: Tier: Premium, Ultimate Offering: Self-managed, GitLab Dedicated

Create and list service account users by using the REST API.

Create a service account user

  • Ability to create a service account user was introduced in GitLab 16.1
  • Ability to specify a username or name was introduced in GitLab 16.10.

Create a service account user. You can specify the account username and name. If you do not specify any attributes:

  • The default name is Service account user.
  • The username is automatically generated.

Prerequisites:

  • You must be an administrator.
POST /service_accounts

Supported attributes:

Attribute Type Required Description
name string no Name of the user.
username string no Username of the user.

Example request:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/service_accounts"

Example response:

{
  "id": 57,
  "username": "service_account_6018816a18e515214e0c34c2b33523fc",
  "name": "Service account user"
}

List all service account users

DETAILS: Tier: Premium, Ultimate Offering: Self-managed, GitLab Dedicated

  • Ability to list all service account users introduced in GitLab 17.1.

Lists all service account users.

Prerequisites:

  • You must be an administrator.

This function takes pagination parameters page and per_page to restrict the list of users.

GET /service_accounts

Supported attributes:

Attribute Type Required Description
order_by string no Order list of users by username or id Default is id.
sort string no Specify sorting by asc or desc. Default is desc.

Example request:

curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/service_accounts"

Example response:

[
  {
    "id": 114,
    "username": "service_account_33",
    "name": "Service account user"
  },
  {
    "id": 137,
    "username": "service_account_34",
    "name": "john doe"
  }
]