Updated on 2025-11-10 GMT+08:00

Adding a Tag to a Security Group

Function

This API is used to create a tag for a security group. The API is idempotent. If a to-be-created tag has the same key as an existing tag, the tag will be created and overwrite the existing one.

Debugging

You can debug this API through automatic authentication in API Explorer.

URI

POST /v2.0/{project_id}/security-groups/{security_group_id}/tags

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID

security_group_id

Yes

String

Security Group ID

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

tag

Yes

ResourceTag object

Request body for creating a security group tag.

Table 3 ResourceTag

Parameter

Mandatory

Type

Description

key

Yes

String

  • Definition: Tag key.

  • Constraints:

    • Cannot be left blank.

    • Can contain a maximum of 128 characters.

    • Must be unique for each resource.

    • Can contain letters, digits, underscores (_), and hyphens (-).

value

Yes

String

  • Definition: Tag value.

  • Constraints:

    • Can contain a maximum of 255 characters.

    • Can contain letters, digits, underscores (_), periods (.), and hyphens (-).

Response Parameters

Status code: 204

The response to the request is normal. For more status codes, see Status Codes.

None

Example Requests

Creating a Tag for a Security Group

POST https://{Endpoint}/v2.0/{project_id}/security-groups/{security_group_id}/tags

{
  "tag" : {
    "key" : "key1",
    "value" : "value1"
  }
}

Example Responses

None

Status Codes

Status Code

Description

204

The response to the request is normal. For more status codes, see Status Codes.

Error Codes

See Error Codes.