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

112 lines
2.6 KiB
Markdown
Raw Normal View History

2017-09-28 16:49:42 +00:00
# Custom Attributes API
Every API call to custom attributes must be authenticated as administrator.
2017-09-18 13:03:24 +00:00
Custom attributes are currently available on users and projects, which will
be 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
```
GET /users/: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
```bash
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/users/42/custom_attributes
```
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
```
GET /users/: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 |
```bash
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/users/42/custom_attributes/location
```
Example response:
```json
{
"key": "location",
"value": "Antarctica"
}
```
## Set custom attribute
2017-09-18 13:03:24 +00:00
Set a custom attribute on a resource. The attribute will be updated if it already exists,
2017-09-28 16:49:42 +00:00
or newly created otherwise.
```
PUT /users/: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 |
```bash
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" --data "value=Greenland" https://gitlab.example.com/api/v4/users/42/custom_attributes/location
```
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
```
DELETE /users/: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 |
```bash
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/users/42/custom_attributes/location
```