ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
# Custom Attributes API > 原文:[https://docs.gitlab.com/ee/api/custom_attributes.html](https://docs.gitlab.com/ee/api/custom_attributes.html) * [List custom attributes](#list-custom-attributes) * [Single custom attribute](#single-custom-attribute) * [Set custom attribute](#set-custom-attribute) * [Delete custom attribute](#delete-custom-attribute) # Custom Attributes API[](#custom-attributes-api "Permalink") 每个对自定义属性的 API 调用都必须经过管理员身份验证. 自定义属性当前可用于用户,组和项目,在本文档中将其称为"资源". ## List custom attributes[](#list-custom-attributes "Permalink") 获取资源上的所有自定义属性. ``` 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[](#single-custom-attribute "Permalink") 在资源上获取单个自定义属性. ``` 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[](#set-custom-attribute "Permalink") 在资源上设置自定义属性. 如果该属性已经存在,则将对其进行更新;否则,将重新创建该属性. ``` 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-custom-attribute "Permalink") 删除资源上的自定义属性. ``` 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" ```