Help us learn about your current experience with the documentation. Take the survey.
自定义属性 API
- 版本:Free, Premium, Ultimate
- 产品:GitLab Self-Managed, GitLab Dedicated
所有对自定义属性的 API 调用都必须以管理员身份进行身份验证。
自定义属性目前可用于用户、群组和项目,在本文档中,这些对象统称为“资源”。
列出自定义属性
获取某个资源上的所有自定义属性。
GET /users/:id/custom_attributes
GET /groups/:id/custom_attributes
GET /projects/:id/custom_attributes| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
id |
integer | 是 | 资源的 ID |
curl --request GET \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/users/42/custom_attributes"示例响应:
[
{
"key": "location",
"value": "Antarctica"
},
{
"key": "role",
"value": "Developer"
}
]获取单个自定义属性
获取某个资源上的单个自定义属性。
GET /users/:id/custom_attributes/:key
GET /groups/:id/custom_attributes/:key
GET /projects/:id/custom_attributes/:key| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
id |
integer | 是 | 资源的 ID |
key |
string | 是 | 自定义属性的键 |
curl --request GET \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"示例响应:
{
"key": "location",
"value": "Antarctica"
}设置自定义属性
为某个资源设置自定义属性。如果该属性已存在,则更新它;否则,将创建一个新属性。
PUT /users/:id/custom_attributes/:key
PUT /groups/:id/custom_attributes/:key
PUT /projects/:id/custom_attributes/:key| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
id |
integer | 是 | 资源的 ID |
key |
string | 是 | 自定义属性的键 |
value |
string | 是 | 自定义属性的值 |
curl --request PUT \
--header "PRIVATE-TOKEN: <your_access_token>" \
--data "value=Greenland" \
--url "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"示例响应:
{
"key": "location",
"value": "Greenland"
}删除自定义属性
删除某个资源上的自定义属性。
DELETE /users/:id/custom_attributes/:key
DELETE /groups/:id/custom_attributes/:key
DELETE /projects/:id/custom_attributes/:key| 属性 | 类型 | 必填 | 描述 |
|---|---|---|---|
id |
integer | 是 | 资源的 ID |
key |
string | 是 | 自定义属性的键 |
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"