Adds tags to resources.

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 headers

This operation uses only common request headers. For more information, see Common request parameters and common response parameters.

Request syntax

POST /tags HTTP/1.1

Request parameters

Parameter Type Position Required Example Description
RegionId String FormData No cn-beijing

The ID of the region.

ResourceType String FormData Yes application

The type of the resource. Set the value to application.

Tags String FormData No [{"key":"k1","value":"v1"}]

The tag in the format of a key-value pair. This parameter is required if you do not specify the ResourceIds parameter. Descriptions:

  • key: the tag key. It cannot exceed 128 characters in length.
  • value: the tag value. It cannot exceed 128 characters in length.

Tag keys and tag values are case-sensitive. If you specify multiple tags, the system adds all the tags to the specified resources. Each tag key on a resource can have only one tag value. If you attempt to add a tag that has the same key as an existing tag, the value of the existing tag is overwritten.

Tag keys and tag values cannot start with aliyun or acs:, and cannot contain http:// or https://.

ResourceIds String FormData Yes ["d42921c4-5433-4abd-8075-0e536f8b****"]

The resource ID. Separate multiple resource IDs with comma (,). This parameter is required if you do not specify the Tags parameter.

Response parameters

Parameter Type Example Description
RequestId String 91F93257-7A4A-4BD3-9A7E-2F6EAE6D****

The ID of the request.

Message String success

The returned message.

TraceId String 0a98a02315955564772843261e****

The ID of the trace. It can be used to query the details of a request.

Data Boolean true

Indicates that the operation was successful.

ErrorCode String This parameter is left empty.

The error code.

  • The ErrorCode parameter is not returned when the request succeeds.
  • The ErrorCode parameter is returned when the request fails. For more information, see Error codes in this topic.
Code String 200

The HTTP status code. Valid values:

  • 2xx: indicates that the request was successful.
  • 3xx: indicates that the request was redirected.
  • 4xx: indicates that the request was invalid.
  • 5xx: indicates that a server error occurred.
Success Boolean true

Indicates whether tags were added to the specified resources successfully. Valid values:

  • true: indicates that tags were added to the specified resources successfully.
  • false: indicates that tags could not be added to the specified resources.

Examples

Sample requests

POST /tags HTTP/1.1
Host:sae.aliyuncs.com
Content-Type:application/json

RegionId=cn-beijing&ResourceType=application&Tags=[{"key":"k1","value":"v1"}]&ResourceIds=["d42921c4-5433-4abd-8075-0e536f8b****"]

Sample success responses

XML format

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

<TagResourcesResponse>
    <RequestId>91F93257-7A4A-4BD3-9A7E-2F6EAE6D****</RequestId>
    <Message>success</Message>
    <TraceId>0a98a02315955564772843261e****</TraceId>
    <Data>true</Data>
    <Code>200</Code>
    <Success>true</Success>
</TagResourcesResponse>

JSON format

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

{
  "RequestId" : "91F93257-7A4A-4BD3-9A7E-2F6EAE6D****",
  "Message" : "success",
  "TraceId" : "0a98a02315955564772843261e****",
  "Data" : true,
  "Code" : "200",
  "Success" : true
}

Error codes

HttpCode Error code Error message Description
400 Duplicate.TagKey The TagKey contains duplicate keys. The error message returned because the specified tag key already exists. Tag keys must be unique.
400 InvalidParameter.TagKey The specified TagKey is invalid. The error message returned because the tag key is invalid.
400 InvalidParameter.TagValue The specified TagValue is invalid. The error message returned because the tag value is invalid.
400 Missing.TagKey You must specify TagKey. The error message returned because the tag value is left empty.
400 NumberExceed.Tags The maximum number of tags is exceeded. The error message returned because the number of specified tags has reached the upper limit.
400 InvalidResourceType.NotFound The specified resource type is not supported. The error message returned because the specified resource type is not supported.
400 InvalidParameter.Obviously The specified parameter is invalid {%s}. The error message returned because the value of the %s parameter is invalid.
400 NumberExceed.ResourceIds The number of resource IDs cannot exceed 50. The error message returned because the number of resource IDs cannot exceed the limit of 50.

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