Skip to content

Modify Host Label



POST /api/v1/object/hosts/{host}/label/modify

Overview

Replace the entire label collection of the specified infrastructure object. Omitting it or passing an empty array clears the collection.

Before Calling and Usage Steps

These labels are the labels bound to the infrastructure object. They are not for modifying collection Tags, the host name, or raw log fields, nor are they equivalent to directly managing global label permissions. The API Key determines the current workspace. Call the API according to the JSON Body on this page; this legacy route also takes parameters and uses URL parameters to override same-named JSON values or add other fields. The URL does not have the same validation as the Body on this page. Do not treat undeclared compatibility fields as a stable extension contract. Do not mix in URL business parameters.

Requires infrastructure.setManage. host is the object name under the current source. The route path can specify only one single-segment name at a time; you cannot pass an object UUID or a global Tag UUID. Slashes in the name may not match this path even when encoded. source must match the object classification. First read the current collection through Get All Labels, retain the label.name values to keep, and then submit the complete target string array; this is not an incremental append.

Omitting labels or passing [] clears all labels. You cannot use omission to mean "keep the original values". For a non-empty collection, the API first writes to the object query service, then creates global label records for names that are not yet registered; these two steps are not an atomic transaction across services, and if the latter step fails, the object labels may already have taken effect. Duplicate or invalid names may cause database errors. Deduplicate by the actual names and follow the global label naming rules. Clearing only removes the binding from this object; it does not delete global label records.

On success, it always returns true and does not provide the number of affected records or the final object; it does not promise that a 404 will be returned for a nonexistent object, nor does it prove that the cache has been refreshed. Upstream-specific write errors are ignored in the SDK; when the result is unknown, read back to verify, and do not rely solely on true to prove that the actual change occurred.

Route Parameters

Parameter Type Required Description
host string Y Actual URL path parameter; the name in the Body or URL parameters is not used to replace this path value.
Example: host-example
How to obtain or fill in: Copy the name from the object list under the current source, one single-segment name at a time.

Request Headers

Parameter Type Required Description
DF-API-KEY string Y OpenAPI authentication credential for the workspace.
Example: <DF-API-KEY>
How to obtain or fill in: Obtain an OpenAPI Key with the required operation permission from API Key Management in the target workspace.

Body Request Parameters

Parameter Type Required Description
source string Y Required string. Do not omit it or default to all sources just because the path contains hosts.
Allows null: False
Example: HOST
How to obtain or fill in: Use the actual object classification that matches the object, such as host HOST.
labels array Optional array of string elements representing the final complete collection; omit it or pass [] to clear. Do not submit label detail objects or UUIDs. Recursive validation is not declared for array elements, and invalid values are not guaranteed to produce a 406 before processing.
Allows null: False
Example: ["production", "service-api"]
How to obtain or fill in: Get label names from content[object name].labels[].name in the Get All Labels response. The object name must correspond to the path host and the Body source; do not use label UUIDs.

Request Example

curl --request POST 'https://openapi.guance.com/api/v1/object/hosts/host-example/label/modify' \
  -H 'DF-API-KEY: <DF-API-KEY>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"source":"HOST","labels":["production","service-api"]}'

Response

HTTP 200, application/json. The example below shows the main fields that can be read directly.

Field Type Description
content boolean Always true on success; it is not object or label details and does not indicate strong consistency or the number of affected records.
{
  "code": 200,
  "content": true,
  "errorCode": "",
  "message": "",
  "success": true,
  "traceId": "TRACE-EXAMPLE"
}

Error Responses

For authentication, rate limiting, and common request errors, see Common Error Definitions.

The modification calls the upstream label write API, and errors may vary with upstream status; regular 5xx errors are ultimately wrapped as 500. A 404 object-not-found is not always thrown just because the host cannot be found locally. Do not assume idempotency or strong consistency.

HTTP Status errorCode Trigger Condition Message or Response Description Handling
406 ft.ParameterValidationFailed Request field is missing, or the field value violates the declared validation conditions Parameter parsing failed Check the parameter location, field name, type, and value.
400 ft.RequestJsonFormatError Invalid request JSON syntax Request JSON format error Correct the JSON according to content.reason, line, and column.
400 ft.JsonFormatError The request Body is not a JSON object Some JSON file format error Submit source and the target labels array.
500 ft.InternalServerError Label element/storage error or an upstream non-passthrough 5xx Internal error First read the object's current labels to determine which step has been executed, then decide whether to retry; provide the traceId.

Feedback

Is this page helpful?