gitlab-org--gitlab-foss/doc/api/custom_attributes.md

124 lines
3.0 KiB
Markdown
Raw Normal View History

---
stage: Ecosystem
group: Integrations
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
---
# Custom Attributes API **(FREE SELF)**
2017-09-28 16:49:42 +00:00
Every API call to custom attributes must be authenticated as administrator.
2017-09-18 15:07:38 +00:00
Custom attributes are currently available on users, groups, and projects,
which is referred to as "resource" in this documentation.
2017-09-28 16:49:42 +00:00
## List custom attributes
2017-09-18 13:03:24 +00:00
Get all custom attributes on a resource.
2017-09-28 16:49:42 +00:00
```plaintext
2017-09-28 16:49:42 +00:00
GET /users/:id/custom_attributes
2017-09-18 15:07:38 +00:00
GET /groups/:id/custom_attributes
2017-09-18 13:03:24 +00:00
GET /projects/:id/custom_attributes
2017-09-28 16:49:42 +00:00
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-09-18 13:03:24 +00:00
| `id` | integer | yes | The ID of a resource |
2017-09-28 16:49:42 +00:00
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes"
2017-09-28 16:49:42 +00:00
```
Example response:
```json
[
{
"key": "location",
"value": "Antarctica"
},
{
"key": "role",
"value": "Developer"
}
]
```
## Single custom attribute
2017-09-18 13:03:24 +00:00
Get a single custom attribute on a resource.
2017-09-28 16:49:42 +00:00
```plaintext
2017-09-28 16:49:42 +00:00
GET /users/:id/custom_attributes/:key
2017-09-18 15:07:38 +00:00
GET /groups/:id/custom_attributes/:key
2017-09-18 13:03:24 +00:00
GET /projects/:id/custom_attributes/:key
2017-09-28 16:49:42 +00:00
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-09-18 13:03:24 +00:00
| `id` | integer | yes | The ID of a resource |
2017-09-28 16:49:42 +00:00
| `key` | string | yes | The key of the custom attribute |
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"
2017-09-28 16:49:42 +00:00
```
Example response:
```json
{
"key": "location",
"value": "Antarctica"
}
```
## Set custom attribute
Set a custom attribute on a resource. The attribute is updated if it already exists,
2017-09-28 16:49:42 +00:00
or newly created otherwise.
```plaintext
2017-09-28 16:49:42 +00:00
PUT /users/:id/custom_attributes/:key
2017-09-18 15:07:38 +00:00
PUT /groups/:id/custom_attributes/:key
2017-09-18 13:03:24 +00:00
PUT /projects/:id/custom_attributes/:key
2017-09-28 16:49:42 +00:00
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-09-18 13:03:24 +00:00
| `id` | integer | yes | The ID of a resource |
2017-09-28 16:49:42 +00:00
| `key` | string | yes | The key of the custom attribute |
| `value` | string | yes | The value of the custom attribute |
```shell
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 16:49:42 +00:00
```
Example response:
```json
{
"key": "location",
"value": "Greenland"
}
```
## Delete custom attribute
2017-09-18 13:03:24 +00:00
Delete a custom attribute on a resource.
2017-09-28 16:49:42 +00:00
```plaintext
2017-09-28 16:49:42 +00:00
DELETE /users/:id/custom_attributes/:key
2017-09-18 15:07:38 +00:00
DELETE /groups/:id/custom_attributes/:key
2017-09-18 13:03:24 +00:00
DELETE /projects/:id/custom_attributes/:key
2017-09-28 16:49:42 +00:00
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
2017-09-18 13:03:24 +00:00
| `id` | integer | yes | The ID of a resource |
2017-09-28 16:49:42 +00:00
| `key` | string | yes | The key of the custom attribute |
```shell
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"
2017-09-28 16:49:42 +00:00
```