极狐 GitLab

自定义属性 API

Tier: 基础版,专业版,旗舰版

Offering: 私有化部署

使用此 API 管理用户、群组和项目的自定义属性。

先决条件:

  • 您必须是实例的管理员。

列出所有自定义属性#

列出指定资源的所有自定义属性。

plaintext
GET /users/:id/custom_attributes GET /groups/:id/custom_attributes GET /projects/:id/custom_attributes
属性类型是否必需描述
id整数资源的 ID
shell
curl --request GET \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "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": "开发者" 9 } 10]

检索自定义属性#

检索资源的指定自定义属性。

plaintext
GET /users/:id/custom_attributes/:key GET /groups/:id/custom_attributes/:key GET /projects/:id/custom_attributes/:key
属性类型是否必需描述
id整数资源的 ID
key字符串自定义属性的键
shell
curl --request GET \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "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
属性类型是否必需描述
id整数资源的 ID
key字符串自定义属性的键
value字符串自定义属性的值
shell
curl --request PUT \ --header "PRIVATE-TOKEN: <your_access_token>" \ --data "value=Greenland" \ --url "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
属性类型是否必需描述
id整数资源的 ID
key字符串自定义属性的键
shell
curl --request DELETE \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"