Custom Attributes API

原文:https://docs.gitlab.com/ee/api/custom_attributes.html

Custom Attributes API

每个对自定义属性的 API 调用都必须经过管理员身份验证.

自定义属性当前可用于用户,组和项目,在本文档中将其称为”资源”.

List custom attributes

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

  1. GET /users/:id/custom_attributes
  2. GET /groups/:id/custom_attributes
  3. GET /projects/:id/custom_attributes
Attribute Type Required Description
id integer yes 资源的 ID
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes"

响应示例:

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

Single custom attribute

在资源上获取单个自定义属性.

  1. GET /users/:id/custom_attributes/:key
  2. GET /groups/:id/custom_attributes/:key
  3. GET /projects/:id/custom_attributes/:key
Attribute Type Required Description
id integer yes 资源的 ID
key string yes 自定义属性的键
  1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"

响应示例:

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

Set custom attribute

在资源上设置自定义属性. 如果该属性已经存在,则将对其进行更新;否则,将重新创建该属性.

  1. PUT /users/:id/custom_attributes/:key
  2. PUT /groups/:id/custom_attributes/:key
  3. PUT /projects/:id/custom_attributes/:key
Attribute Type Required Description
id integer yes 资源的 ID
key string yes 自定义属性的键
value string yes 自定义属性的值
  1. curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" --data "value=Greenland" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"

响应示例:

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

Delete custom attribute

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

  1. DELETE /users/:id/custom_attributes/:key
  2. DELETE /groups/:id/custom_attributes/:key
  3. DELETE /projects/:id/custom_attributes/:key
Attribute Type Required Description
id integer yes 资源的 ID
key string yes 自定义属性的键
  1. curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"