2020-10-26 17:08:22 -04:00
---
2021-04-23 11:09:37 -04:00
stage: Create
group: Ecosystem
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-10-26 17:08:22 -04:00
---
2017-09-28 12:49:42 -04:00
# Custom Attributes API
Every API call to custom attributes must be authenticated as administrator.
2017-09-18 11:07:38 -04:00
Custom attributes are currently available on users, groups, and projects,
2020-11-19 16:09:07 -05:00
which is referred to as "resource" in this documentation.
2017-09-28 12:49:42 -04:00
## List custom attributes
2017-09-18 09:03:24 -04:00
Get all custom attributes on a resource.
2017-09-28 12:49:42 -04:00
2020-02-27 04:09:01 -05:00
```plaintext
2017-09-28 12:49:42 -04:00
GET /users/:id/custom_attributes
2017-09-18 11:07:38 -04:00
GET /groups/:id/custom_attributes
2017-09-18 09:03:24 -04:00
GET /projects/:id/custom_attributes
2017-09-28 12:49:42 -04:00
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-09-18 09:03:24 -04:00
| `id` | integer | yes | The ID of a resource |
2017-09-28 12:49:42 -04:00
2020-01-30 10:09:15 -05:00
```shell
2020-05-27 20:08:37 -04:00
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/users/42/custom_attributes"
2017-09-28 12:49:42 -04:00
```
Example response:
```json
[
{
"key": "location",
"value": "Antarctica"
},
{
"key": "role",
"value": "Developer"
}
]
```
## Single custom attribute
2017-09-18 09:03:24 -04:00
Get a single custom attribute on a resource.
2017-09-28 12:49:42 -04:00
2020-02-27 04:09:01 -05:00
```plaintext
2017-09-28 12:49:42 -04:00
GET /users/:id/custom_attributes/:key
2017-09-18 11:07:38 -04:00
GET /groups/:id/custom_attributes/:key
2017-09-18 09:03:24 -04:00
GET /projects/:id/custom_attributes/:key
2017-09-28 12:49:42 -04:00
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-09-18 09:03:24 -04:00
| `id` | integer | yes | The ID of a resource |
2017-09-28 12:49:42 -04:00
| `key` | string | yes | The key of the custom attribute |
2020-01-30 10:09:15 -05:00
```shell
2020-05-27 20:08:37 -04:00
curl --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"
2017-09-28 12:49:42 -04:00
```
Example response:
```json
{
"key": "location",
"value": "Antarctica"
}
```
## Set custom attribute
2020-11-19 16:09:07 -05:00
Set a custom attribute on a resource. The attribute is updated if it already exists,
2017-09-28 12:49:42 -04:00
or newly created otherwise.
2020-02-27 04:09:01 -05:00
```plaintext
2017-09-28 12:49:42 -04:00
PUT /users/:id/custom_attributes/:key
2017-09-18 11:07:38 -04:00
PUT /groups/:id/custom_attributes/:key
2017-09-18 09:03:24 -04:00
PUT /projects/:id/custom_attributes/:key
2017-09-28 12:49:42 -04:00
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-09-18 09:03:24 -04:00
| `id` | integer | yes | The ID of a resource |
2017-09-28 12:49:42 -04:00
| `key` | string | yes | The key of the custom attribute |
| `value` | string | yes | The value of the custom attribute |
2020-01-30 10:09:15 -05:00
```shell
2021-06-02 11:09:59 -04:00
curl --request PUT --header "PRIVATE-TOKEN: < your_access_token > " \
--data "value=Greenland" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"
2017-09-28 12:49:42 -04:00
```
Example response:
```json
{
"key": "location",
"value": "Greenland"
}
```
## Delete custom attribute
2017-09-18 09:03:24 -04:00
Delete a custom attribute on a resource.
2017-09-28 12:49:42 -04:00
2020-02-27 04:09:01 -05:00
```plaintext
2017-09-28 12:49:42 -04:00
DELETE /users/:id/custom_attributes/:key
2017-09-18 11:07:38 -04:00
DELETE /groups/:id/custom_attributes/:key
2017-09-18 09:03:24 -04:00
DELETE /projects/:id/custom_attributes/:key
2017-09-28 12:49:42 -04:00
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-09-18 09:03:24 -04:00
| `id` | integer | yes | The ID of a resource |
2017-09-28 12:49:42 -04:00
| `key` | string | yes | The key of the custom attribute |
2020-01-30 10:09:15 -05:00
```shell
2020-05-27 20:08:37 -04:00
curl --request DELETE --header "PRIVATE-TOKEN: < your_access_token > " "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"
2017-09-28 12:49:42 -04:00
```