Creates tags and adds them to resources.

Usage notes

Tags are used to classify instances. Each tag consists of a key and a value. Take note of the following limits when you use tags:

  • The keys of tags that are added to the same instance must be unique.
  • You cannot create tags without adding them to instances. All tags must be added to instances.
  • Tag information is not shared across regions.

    For example, in the China (Shanghai) region, you cannot view the tags that are created in the China (Hangzhou) region.

  • Virtual private clouds (VPCs), route tables, vSwitches, and elastic IP addresses (EIPs) that belong to the same Alibaba Cloud account and are deployed in the same region share tag information with each other.

    For example, if you added a tag to a VPC, the tag is available to vSwitches, route tables, and EIPs that belong to the same account and are deployed in the same region in which the VPC is created. You can select this tag from the editing page without the need to enter the tag again. You can modify the key and value of a tag or remove a tag from an instance. After you delete an instance, all tags that are added to the instance are deleted.

  • You can add up to 20 tags to each instance. Before you add a tag to an instance, the system automatically checks the number of existing tags. An error message is returned if the maximum number of tags is reached.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
ResourceType String Yes VPC

The type of the resource. Valid values:

  • VPC: a VPC
  • VSWITCH: a vSwitch
  • ROUTETABLE: a route table
  • EIP: an EIP
  • VpnGateway: a VPN gateway
  • NATGATEWAY: a NAT gateway
  • COMMONBANDWIDTHPACKAGE: an EIP bandwidth plan
RegionId String Yes cn-hangzhou

The region ID of the resource.

You can call the DescribeRegions operation to query the most recent region list.

Action String Yes TagResources

The operation that you want to perform. Set the value to TagResources.

ResourceId.N String Yes vpc-bp16qjewdsunr41m1****

The ID of the resource. You can specify up to 20 IDs.

Tag.N.Key String No FinanceDept

The key of the tag that is added to the resource. You can specify at most 20 tag keys. The tag value cannot be an empty string.

The key cannot exceed 64 characters in length, and can contain digits, periods (.), underscores (_), and hyphens (-). The key must start with a letter but cannot start with aliyun or acs:. The key cannot contain http:// or https://.

Tag.N.Value String No FinanceJoshua

The value of the tag that is added to the resource. You can specify at most 20 tag values. The tag value can be an empty string.

The tag value cannot exceed 128 characters in length, and can contain digits, periods (.), underscores (_), and hyphens (-). The key must start with a letter but cannot start with aliyun or acs:. The key cannot contain http:// or https://.

Response parameters

Parameter Type Example Description
RequestId String C46FF5A8-C5F0-4024-8262-B16B639225A0

The ID of the request.

Examples

Sample requests

http(s)://[Endpoint]/?ResourceType=VPC
&RegionId=cn-hangzhou
&Action=TagResources
&ResourceId=["vpc-bp16qjewdsunr41m1****"]
&Tag=[{"Key":"FinanceDept","Value":"FinanceJoshua"}]
&Common request parameters

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<TagResourcesResponse>
    <RequestId>C46FF5A8-C5F0-4024-8262-B16B639225A0</RequestId>
</TagResourcesResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "C46FF5A8-C5F0-4024-8262-B16B639225A0"
}

Error codes

HttpCode Error code Error message Description
400 InvalidTagKey The tag keys are not valid. The error message returned because the tag index is invalid.
400 InvalidTagValue The tag values are not valid. The error message returned because the tag value is invalid.
400 InvalidInstanceType.NotFound The instance type is not found The error message returned because the instance type is not found.
400 InvalidInstanceIds.NotFound The instanceIds are not found The error message returned because the instance ID is not found.
400 Forbidden.TagKeys The request do not allow to operate the tag keys The error message returned because you do not have the permissions to set the TagKeys parameter.
400 QuotaExceeded.TagNum Custom Tags quota exceeded The error message returned because the quota is reached.
400 InvalidTagScope.NotFound The tag scope is not found The error message returned because the resource scope is invalid.
400 Forbidden.TagKey.Duplicated The specified tag key already exists. The error message returned because the tag key already exists.
400 SizeLimitExceeded.TagNum The maximum number of tags is exceeded. The error message returned because the specified number of tags exceeds the upper limit.
400 SizeLimitExceeded.ResourceId The maximum number of resource IDs is exceeded. The error message returned because the specified number of resource group IDs exceeds the upper limit.
400 MissingParameter.TagValue The input parameter TagValue that is mandatory for processing this request is not supplied. The error message returned because the TagValue parameter is not set.
400 MissingParameter.TagKey The input parameter TagKey that is mandatory for processing this request is not supplied. The error message returned because the TagKey parameter is not set.
403 Forbidden User not authorized to operate on the specified resource. The error message returned because you are unauthorized to perform the operation on the specified resource. Acquire the required permissions and try again.

For a list of error codes, visit the API Error Center.