自定义属性 API

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

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

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

列出自定义属性#

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

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

示例响应:

json
1[ 2 { 3 "key": "location", 4 "value": "Antarctica" 5 }, 6 { 7 "key": "role", 8 "value": "Developer" 9 } 10]

单个自定义属性#

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

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

示例响应:

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

设置自定义属性#

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

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

示例响应:

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

删除自定义属性#

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

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