自定义属性 API
- Tier: 基础版,专业版,旗舰版
- Offering: 私有化部署
每个对自定义属性的 API 调用必须以管理员身份进行身份验证。
自定义属性目前可用于用户、群组和项目,在本文档中被称为“资源”。
列出自定义属性
获取资源上的所有自定义属性。
plaintextGET /users/:id/custom_attributes GET /groups/:id/custom_attributes GET /projects/:id/custom_attributes
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer | 是 | 资源的 ID |
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes"
示例响应:
json1[ 2 { 3 "key": "location", 4 "value": "Antarctica" 5 }, 6 { 7 "key": "role", 8 "value": "Developer" 9 } 10]
单个自定义属性
获取资源上的单个自定义属性。
plaintextGET /users/:id/custom_attributes/:key GET /groups/:id/custom_attributes/:key GET /projects/:id/custom_attributes/:key
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer | 是 | 资源的 ID |
| key | string | 是 | 自定义属性的键 |
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"
示例响应:
json{ "key": "location", "value": "Antarctica" }
设置自定义属性
在资源上设置自定义属性。如果属性已经存在,则更新,否则新创建。
plaintextPUT /users/:id/custom_attributes/:key PUT /groups/:id/custom_attributes/:key PUT /projects/:id/custom_attributes/:key
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer | 是 | 资源的 ID |
| key | string | 是 | 自定义属性的键 |
| value | string | 是 | 自定义属性的值 |
shellcurl --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" }
删除自定义属性
删除资源上的自定义属性。
plaintextDELETE /users/:id/custom_attributes/:key DELETE /groups/:id/custom_attributes/:key DELETE /projects/:id/custom_attributes/:key
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer | 是 | 资源的 ID |
| key | string | 是 | 自定义属性的键 |
shellcurl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"