{{< details >}}

  • Tier: 基础版,专业版,旗舰版
  • Offering: 私有化部署

{{< /details >}}

每个对自定义属性的 API 调用必须以管理员身份进行身份验证。

自定义属性目前可用于用户、群组和项目,在本文档中被称为“资源”。

列出自定义属性

获取资源上的所有自定义属性。

GET /users/:id/custom_attributes
GET /groups/:id/custom_attributes
GET /projects/:id/custom_attributes
属性 类型 必需 描述
id integer 资源的 ID
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes"

示例响应:

[
   {
      "key": "location",
      "value": "Antarctica"
   },
   {
      "key": "role",
      "value": "Developer"
   }
]

单个自定义属性

获取资源上的单个自定义属性。

GET /users/:id/custom_attributes/:key
GET /groups/:id/custom_attributes/:key
GET /projects/:id/custom_attributes/:key
属性 类型 必需 描述
id integer 资源的 ID
key string 自定义属性的键
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"

示例响应:

{
   "key": "location",
   "value": "Antarctica"
}

设置自定义属性

在资源上设置自定义属性。如果属性已经存在,则更新,否则新创建。

PUT /users/:id/custom_attributes/:key
PUT /groups/:id/custom_attributes/:key
PUT /projects/:id/custom_attributes/:key
属性 类型 必需 描述
id integer 资源的 ID
key string 自定义属性的键
value string 自定义属性的值
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" \
     --data "value=Greenland" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"

示例响应:

{
   "key": "location",
   "value": "Greenland"
}

删除自定义属性

删除资源上的自定义属性。

DELETE /users/:id/custom_attributes/:key
DELETE /groups/:id/custom_attributes/:key
DELETE /projects/:id/custom_attributes/:key
属性 类型 必需 描述
id integer 资源的 ID
key string 自定义属性的键
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"