Updated on 2026-03-19 GMT+08:00

Adding Tags to an ECS in a Batch

Function

  • This API is used to add tags to a specified ECS in a batch.
  • The Tag Management Service (TMS) uses this API to batch manage the tags of an ECS.

Constraints

  • An ECS allows a maximum of 20 tags.
  • This API is idempotent.

    During tag creation, if a tag exists (both the key and value are the same as those of an existing tag), the tag is successfully processed by default.

  • A new tag will overwrite the original one if their keys are the same and values are different.
  • This API supports checking fine-grained permissions for enterprise projects. For details, see ecs:cloudServers:batchSetServerTags.

Debugging

You can debug this API in API Explorer.

Authorization

Each account has all of the permissions required to call all APIs, but IAM users must have the required permissions specifically assigned.
  • If you are using role/policy-based authorization, see the required permissions in Permissions and Supported Actions.
  • If you are using identity policy-based authorization, the permissions listed below are required.

Action

Access Level

Resource Type (*: required)

Condition Key

Alias

Dependencies

ecs:cloudServers:batchCreateServerTags

write

instance *

  • g:RequestTag/<tag-key>
  • g:TagKeys
  • ecs:cloudServers:put
  • ecs:cloudServers:batchSetServerTags

-

URI

POST /v1/{project_id}/cloudservers/{server_id}/tags/action

Table 1 describes the parameters in the URI.
Table 1 Parameter description

Parameter

Mandatory

Description

project_id

Yes

Definition

Specifies the project ID.

For details about how to obtain the ID, see Obtaining a Project ID.

Constraints

N/A

Range

N/A

Default Value

N/A

server_id

Yes

Definition

Specifies the ECS ID.

Constraints

N/A

Range

N/A

Default Value

N/A

Request

Table 2 describes the request parameters.

Table 2 Request parameters

Parameter

Mandatory

Type

Description

tags

Yes

Array of objects

Definition

Specifies tags. For details, see Table 3.

Constraints

N/A

Range

N/A

Default Value

N/A

action

Yes

String

Definition

Specifies the operation identifier.

Constraints

Only lowercase letters are supported.

Range

create

Default Value

N/A

Table 3 tags field description

Parameter

Mandatory

Type

Description

key

Yes

String

Definition

Specifies the tag key.

Constraints

  • It cannot be left blank.
  • It must be unique for each resource.
  • It must be unique and cannot be left blank.

Range

  • A maximum of 128 characters are supported.
  • Only uppercase letters, lowercase letters, digits, hyphens (-), underscores (_), and Unicode characters (\u4E00-\u9FFF) are supported.
  • The following special characters are not supported: =*<>\,|/

Default Value

N/A

value

No

String

Definition

Specifies the tag value.

Constraints

N/A

Range

  • A maximum of 255 characters are supported.
  • Only uppercase letters, lowercase letters, digits, periods (.), hyphens (-), underscores (_), and Unicode characters (\u4E00-\u9FFF) are supported.
  • The following special characters are not supported:: =*<>\,|

Default Value

N/A

Response

None

Example Request

Batch add two pairs of tags to a specified ECS.

POST  https://{endpoint}/v1/{project_id}/cloudservers/{server_id}/tags/action

{
    "action": "create",
    "tags": [
        {
            "key": "key1",
            "value": "value1"
        },
        {
            "key": "key2",
            "value": "value3"
        }
    ]
}

Example Response

None

Error Codes

See Error Codes.