Custom Attributes API
Custom Attributes API
每个对自定义属性的 API 调用都必须经过管理员身份验证.
自定义属性当前可用于用户,组和项目,在本文档中将其称为"资源".
List custom attributes
获取资源上的所有自定义属性.
GET /users/:id/custom_attributes
GET /groups/:id/custom_attributes
GET /projects/:id/custom_attributes 
| Attribute | Type | Required | Description | 
|---|---|---|---|
 id  | 
integer | yes | 资源的 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"  }  ] 
Single custom attribute
在资源上获取单个自定义属性.
GET /users/:id/custom_attributes/:key
GET /groups/:id/custom_attributes/:key
GET /projects/:id/custom_attributes/:key 
| Attribute | Type | Required | Description | 
|---|---|---|---|
 id  | 
integer | yes | 资源的 ID | 
 key  | 
string | yes | 自定义属性的键 | 
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location" 
响应示例:
{  "key":  "location",  "value":  "Antarctica"  } 
Set custom attribute
在资源上设置自定义属性. 如果该属性已经存在,则将对其进行更新;否则,将重新创建该属性.
PUT /users/:id/custom_attributes/:key
PUT /groups/:id/custom_attributes/:key
PUT /projects/:id/custom_attributes/:key 
| Attribute | Type | Required | Description | 
|---|---|---|---|
 id  | 
integer | yes | 资源的 ID | 
 key  | 
string | yes | 自定义属性的键 | 
 value  | 
string | yes | 自定义属性的值 | 
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 custom attribute
删除资源上的自定义属性.
DELETE /users/:id/custom_attributes/:key
DELETE /groups/:id/custom_attributes/:key
DELETE /projects/:id/custom_attributes/:key 
| Attribute | Type | Required | Description | 
|---|---|---|---|
 id  | 
integer | yes | 资源的 ID | 
 key  | 
string | yes | 自定义属性的键 | 
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"