---
title: "LabelApi"
lastmod: 2026-05-29
canonical: "https://container-registry.com/docs/harbor-api-client/api/labelapi/"
source: "https://container-registry.com/docs/harbor-api-client/api/labelapi/index.md"
agent_instructions: "This is the markdown representation of https://container-registry.com/docs/harbor-api-client/api/labelapi/index.md. Prefer this version over scraping the HTML. The site index is at https://container-registry.com/llms.txt."
---

> Agent-friendly representation of <https://container-registry.com/docs/harbor-api-client/api/labelapi/index.md>. Site index: <https://container-registry.com/llms.txt>.

# harbor_client.LabelApi

All URIs are relative to *http://localhost/api/v2.0*

Method | HTTP request | Description
------------- | ------------- | -------------
[**create_label**](#create_label) | **POST** /labels | Post creates a label
[**delete_label**](#delete_label) | **DELETE** /labels/{label_id} | Delete the label specified by ID.
[**get_label_by_id**](#get_label_by_id) | **GET** /labels/{label_id} | Get the label specified by ID.
[**list_labels**](#list_labels) | **GET** /labels | List labels according to the query strings.
[**update_label**](#update_label) | **PUT** /labels/{label_id} | Update the label properties.


# **create_label**

### Signature

```python
create_label(label: Label, x_request_id: Optional[str])-> None
```

Post creates a label

This endpoint let user creates a label. 

### Example
```python
from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.LabelApi(harbor_client.ApiClient(configuration))
label = harbor_client.Label() # Label | The json object of label.
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Post creates a label
    api_instance.create_label(label, x_request_id=x_request_id)
except ApiException as e:
    print("Exception when calling LabelApi->create_label: %s\n" % e)
```

### Parameters

Name | Type | Description  | Notes
------------- | ------------- | ------------- | -------------
 **label** | **[Label](../../model/label/)**| The json object of label. | 
 **x_request_id** | **str**| An unique ID for the request | [optional] 

### Return type

void (empty response body)

### Authorization

[basic](../../#basic)

### HTTP request headers

 - **Content-Type**: application/json
 - **Accept**: application/json

[[Back to top]](#)

# **delete_label**

### Signature

```python
delete_label(label_id: int, x_request_id: Optional[str])-> None
```

Delete the label specified by ID.

Delete the label specified by ID. 

### Example
```python
from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.LabelApi(harbor_client.ApiClient(configuration))
label_id = 789 # int | Label ID
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Delete the label specified by ID.
    api_instance.delete_label(label_id, x_request_id=x_request_id)
except ApiException as e:
    print("Exception when calling LabelApi->delete_label: %s\n" % e)
```

### Parameters

Name | Type | Description  | Notes
------------- | ------------- | ------------- | -------------
 **label_id** | **int**| Label ID | 
 **x_request_id** | **str**| An unique ID for the request | [optional] 

### Return type

void (empty response body)

### Authorization

[basic](../../#basic)

### HTTP request headers

 - **Content-Type**: application/json
 - **Accept**: application/json

[[Back to top]](#)

# **get_label_by_id**

### Signature

```python
get_label_by_id(label_id: int, x_request_id: Optional[str])-> Label
```

Get the label specified by ID.

This endpoint let user get the label by specific ID. 

### Example
```python
from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.LabelApi(harbor_client.ApiClient(configuration))
label_id = 789 # int | Label ID
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Get the label specified by ID.
    api_response = api_instance.get_label_by_id(label_id, x_request_id=x_request_id)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling LabelApi->get_label_by_id: %s\n" % e)
```

### Parameters

Name | Type | Description  | Notes
------------- | ------------- | ------------- | -------------
 **label_id** | **int**| Label ID | 
 **x_request_id** | **str**| An unique ID for the request | [optional] 

### Return type

**[Label](../../model/label/)**

### Authorization

[basic](../../#basic)

### HTTP request headers

 - **Content-Type**: application/json
 - **Accept**: application/json

[[Back to top]](#)

# **list_labels**

### Signature

```python
list_labels(x_request_id: Optional[str], q: Optional[str], sort: Optional[str], page: Optional[int], page_size: Optional[int], name: Optional[str], scope: Optional[str], project_id: Optional[int])-> list[Label]
```

List labels according to the query strings.

This endpoint let user list labels by name, scope and project_id 

### Example
```python
from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.LabelApi(harbor_client.ApiClient(configuration))
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)
q = 'q_example' # str | Query string to query resources. Supported query patterns are \"exact match(k=v)\", \"fuzzy match(k=~v)\", \"range(k=[min~max])\", \"list with union releationship(k={v1 v2 v3})\" and \"list with intersetion relationship(k=(v1 v2 v3))\". The value of range and list can be string(enclosed by \" or '), integer or time(in format \"2020-04-09 02:36:00\"). All of these query patterns should be put in the query string \"q=xxx\" and splitted by \",\". e.g. q=k1=v1,k2=~v2,k3=[min~max] (optional)
sort = 'sort_example' # str | Sort the resource list in ascending or descending order. e.g. sort by field1 in ascending orderr and field2 in descending order with \"sort=field1,-field2\" (optional)
page = 1 # int | The page number (optional) (default to 1)
page_size = 10 # int | The size of per page (optional) (default to 10)
name = 'name_example' # str | The label name. (optional)
scope = 'scope_example' # str | The label scope. Valid values are g and p. g for global labels and p for project labels. (optional)
project_id = 789 # int | Relevant project ID, required when scope is p. (optional)

try:
    # List labels according to the query strings.
    api_response = api_instance.list_labels(x_request_id=x_request_id, q=q, sort=sort, page=page, page_size=page_size, name=name, scope=scope, project_id=project_id)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling LabelApi->list_labels: %s\n" % e)
```

### Parameters

Name | Type | Description  | Notes
------------- | ------------- | ------------- | -------------
 **x_request_id** | **str**| An unique ID for the request | [optional] 
 **q** | **str**| Query string to query resources. Supported query patterns are \&quot;exact match(k&#x3D;v)\&quot;, \&quot;fuzzy match(k&#x3D;~v)\&quot;, \&quot;range(k&#x3D;[min~max])\&quot;, \&quot;list with union releationship(k&#x3D;{v1 v2 v3})\&quot; and \&quot;list with intersetion relationship(k&#x3D;(v1 v2 v3))\&quot;. The value of range and list can be string(enclosed by \&quot; or &#39;), integer or time(in format \&quot;2020-04-09 02:36:00\&quot;). All of these query patterns should be put in the query string \&quot;q&#x3D;xxx\&quot; and splitted by \&quot;,\&quot;. e.g. q&#x3D;k1&#x3D;v1,k2&#x3D;~v2,k3&#x3D;[min~max] | [optional] 
 **sort** | **str**| Sort the resource list in ascending or descending order. e.g. sort by field1 in ascending orderr and field2 in descending order with \&quot;sort&#x3D;field1,-field2\&quot; | [optional] 
 **page** | **int**| The page number | [optional] [default to 1]
 **page_size** | **int**| The size of per page | [optional] [default to 10]
 **name** | **str**| The label name. | [optional] 
 **scope** | **str**| The label scope. Valid values are g and p. g for global labels and p for project labels. | [optional] 
 **project_id** | **int**| Relevant project ID, required when scope is p. | [optional] 

### Return type

**[list[Label]](../../model/label/)**

### Authorization

[basic](../../#basic)

### HTTP request headers

 - **Content-Type**: application/json
 - **Accept**: application/json

[[Back to top]](#)

# **update_label**

### Signature

```python
update_label(label_id: int, label: Label, x_request_id: Optional[str])-> None
```

Update the label properties.

This endpoint let user update label properties. 

### Example
```python
from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.LabelApi(harbor_client.ApiClient(configuration))
label_id = 789 # int | Label ID
label = harbor_client.Label() # Label | The updated label json object.
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Update the label properties.
    api_instance.update_label(label_id, label, x_request_id=x_request_id)
except ApiException as e:
    print("Exception when calling LabelApi->update_label: %s\n" % e)
```

### Parameters

Name | Type | Description  | Notes
------------- | ------------- | ------------- | -------------
 **label_id** | **int**| Label ID | 
 **label** | **[Label](../../model/label/)**| The updated label json object. | 
 **x_request_id** | **str**| An unique ID for the request | [optional] 

### Return type

void (empty response body)

### Authorization

[basic](../../#basic)

### HTTP request headers

 - **Content-Type**: application/json
 - **Accept**: application/json

[[Back to top]](#)


